Tag Info

Hot answers tagged

11

The shell is just a program, although it plays an important role in the system. Bash, and I would assume most other common shells, are implemented in C. The two most important native C system calls that are used in the creation of subprocesses are fork() and exec(). These functions are usually implemented in higher level languages too, including shell. ...


7

The primary issue here -- which accounts for why, e.g., $PS1 is not reported by env -- is that env is reporting from a non-interactive environment. Processes are executed from a fork of your interactive shell, but there's a subtlety involved in how their environment is set: It's actually inherited via a native C level external variable set for all exec()'d ...


6

You can use: kill -TERM -- -XXX where XXX is group number of process group you want to kill. You can check it using: $ ps x -o "%p %r %c" PID PGID COMMAND 2416 1272 gnome-keyring-d 2427 2427 gnome-session 2459 2427 lightdm-session <defunct> 2467 2467 ssh-agent 2470 2427 dbus-launch 2471 2471 dbus-daemon 2484 2427 gnome-settings- ...


6

If so, what about built-in commands like cd? If cd is executed on a child process Herein lies the flaw in your logic. cd, being a shell builtin, is interpreted specially by the shell and "executed" in-process. You can use the type command to find out whether a command is builtin or not.


4

foo & bg_pid=$! kill "$bg_pid" You can also use the shell's internal kill command with (at least in case of bash) the job number: foo & kill %1 But that's probably not easier. May be easier interactively. But with kill %+ or kill % you always get the last one. You can even identify the job to be killed by parts of the command line. See man ...


4

Root and non root privileges are all user space related things. For example, a root user can install an application and an ordinary user can't. However, even the root user has some limitations. Those limitations are imposed by the design of the operating system do differentiate between user space and kernel space. For example, even dough you are a root ...


4

The output from the locale command is not a list of environment variables from the current environment. It is a display of that process' effective locale settings (which is influenced in part by certain environment variables) and is presented in the same key=value format that the env command uses. You can see the source for the eglibc locale command ...


4

The shell knows two types of variables: "internal" variables which are known to the shell only (and to subshells) exported variables, the "official" ones which are seen by execve and thus by env. The shell builtin export shows you the exported variables. If you execute export PS1 and repeat env | grep "PS1" then you see it. Variables can be ...


4

If you know the parent processes PID you can do this using pkill. Example $ pkill -TERM -P 27888 Where the PPID is 27888. excerpt from pkill man -P, --parent ppid,... Only match processes whose parent process ID is listed. What's my PID in a script? This is probably your next question so when in a Bash script you can find out the ...


3

If I suspend my OS (Ubuntu 12.04) in the middle, will the process of the running program be killed? Generally no, but there are some exceptions to this, e.g., if ssh connections have timed out, those will die when you resume. I've also occasionally noticed a weird one with a server process that uses epoll() on a non-blocking socket (don't know if ...


3

Create a PID namespace The correct command to use here is unshare. Note that the necessary options to do this are only available from util-linux 2.23. The idea is to create a new PID namespace for the program you are running such that all its children are also created in this namespace. You can run a command in a new PID namespace simply by doing: sudo ...


3

The /proc/PID/fd/NUM symlinks are quasi-universal on Linux, but they don't exist anywhere else (except on Cygwin which emulates them). /proc/PID/fd/NUM also exist on AIX and Solaris, but they aren't symlinks. Portably, to get information about open files, install lsof. Unices with /proc/PID/fd Linux Under Linux, /proc/PID/fd/NUM is a slightly magic ...


3

The way /proc is implemented and the features it provides is not standardized in any way, see for instance https://blogs.oracle.com/eschrock/entry/the_power_of_proc. According to Wikipedia, FreeBSD is "phasing out" /proc, see http://lists.freebsd.org/pipermail/freebsd-fs/2011-February/010760.html . As of /dev, /dev/fd/ is not part of POSIX or the Single ...


3

NOTE: ALL THE BELOW INFORMATION IS FROM THE REFERENCED SITE From this link, I found the below information. A system call is an interface between a user-space application and a service that the kernel provides. Because the service is provided in the kernel, a direct call cannot be performed; instead, you must use a process of crossing the ...


2

Chris' answer would work if the process is long-lived, and you have time to go inspect it, but if it's a short running command, it may be difficult to catch it while the process is still alive. Another way you could approach this is to put a 'wrapper' around the program. Lets say the program being called is /usr/bin/someprog. Move /usr/bin/someprog to ...


2

If you run a fake job such as sleep 120 and then watch it in htop you'll notice that its state is S aka "SLEEP" and the processes TIME remains at 0:00.00 for the duration. That's because that process is consuming 0 CPU time, which is the intent of the TIME column. It tracks the amount of CPU time a given process has used. ...


2

While I don't know of a way to limit the number of processes by name, you may be able to accomplish your overall goal via pam_limits by limiting the number of user logins. An entry in /etc/security/limits such as @remotes hard maxlogins 5 will ensure that the users of the remotes group cannot have more than 5 login sessions on the ...


2

That's expected behavior. cpulimit suspends the process when it consumes too much CPU resource and resume the process after a certain amount of time. Also check if your script is waiting for input? If so, your script will enter a stopped state as well. Try redirect stdin and run cpulimit again, e.g python run.py < /dev/null &


2

(I'll try to be brief.) In theory, there are two dimensions of privileges: The computer's instruction set architecture (ISA), which protects certain information and/or functions of the machine. The operating system (OS) creating an eco-system for applications and communication. At its core is the kernel, a program that can run on the ISA with no ...


2

The best way to do this is to use systemd (or another way using cgroups) for starting and stopping the application. A process can leave its process group but can never (at least not without root privilege) leave its cgroup. Thus systemd creates a new cgroup for the new process and later simply kills everything in the cgroup.


2

To get some version information, find pgrep in your PATH and run the command what. I get: % what /usr/bin/pgrep /usr/bin/pgrep PROGRAM:pkill PROJECT:adv_cmds-149 Note that the program name is pkill. pkill and pgrep are hard links to the same binary on my system (OS X). Explanation (from the manual): NAME what -- show what versions of ...


1

In general this information cannot be obtained. print.sh can easily determine that its input is coming from a pipe, but not what is at the other end of the pipe. The first process may even have terminated, with its output fully contained in the pipe buffer. In this case, not even traversing the process list will give you any information. Whatever it is ...


1

Update This is one of those ones where I clearly should have read the question more carefully (though seemingly this is the case with most answers on to this question). I have left the original answer intact because it gives some good information, even though it clearly misses the point of the question. Using SID I think the most general, robust approach ...


1

${PROC_CMD} & pid=$! kids=$(grep -l "PPid.*$$" /proc/*/status | grep -o "[0-9]*" for kid in $(cat /proc/$pid/task/*/children); do kids="$kid $kids $(cat /proc/$kid/task/*/children)" done printf '%s ' $kids) kill $kids That kills all children of ${PROC_CMD}, which is backgrounded in the first line and its $pid captured in the next. ...


1

You'd probably be better off with nice as the way cpulimit is a bit of a hack and may play poorly with shell job control and other mechanisms. Since nice is a capability of the operating system which alters the scheduling priorities, this is much smoother than what cpulimit does which is allow a process to run as fast as it wants until it has exceeded a ...


1

As mentioned in one of the answers to your previous question, the exec family call happens after the child process is created, so if you want it to appear in the strace output then you have to make it also follow children of the shell process you are tracing. You can do this by adding either the -f or -ff options, here are the relevant man page snippets: ...


1

just remove the & at then end of towhee towhee_input5 > output & In shell & means to put in background execution, if you want you process to run in foreground then just remove it and your script will go one once it ends. edit If you want to run the command in background and wait for it, then simply use wait towhee towhee_input5 > ...


1

Modern init systems such as systemd and upstart run multiple threads of execution, and even with the original init, things may be forked during the boot process (you've already said yours does, for example). This means your process is running at the same time as other processes, and any output will be interleaved with their's: Process 1 says "I'm here" ...


1

You can use the jps command: jps | grep "[0-9][0-9]* js-test-driver" However, it might not be called js-test-driver, it might be something like js-test-driver.jar. Try looking at the output of just jps first.



Only top voted, non community-wiki answers of a minimum length are eligible