Tag Info

Hot answers tagged

33

It's to simplify the interface. The alternative to fork and exec would be something like Windows' CreateProcess function. Notice how many parameters CreateProcess has, and many of them are structs with even more parameters. This is because everything you might want to control about the new process has to be passed to CreateProcess. In fact, CreateProcess ...


19

Generally, you should use kill -15 before kill -9 so as to give the program a chance to clean up after itself. (Programs can't catch or ignore SIGKILL, but they can and often do catch SIGTERM.) If you don't give the program a chance to finish what it's doing and clean up, it may leave corrupted files around that it won't be able to understand once ...


16

Randal Schwartz used to frequently post "Useless use of (x)" on lists. One such post was about kill -9. It includes reasons and a recipe to follow. Here is a reconstructed version (quoted below). (Quote abomination) No no no. Don't use kill -9. It doesn't give the process a chance to cleanly: 1) shut down socket connections 2) clean up temp files ...


16

Yes on both counts. Many processes are short lived. They get a PID, run, finish, and the PID disappears from the process table. Processes sometimes only live for a fraction of a second! Often when programs start they run numerous commands as part of checking the system and initializing their environment. The maximum PID number depends on the system and ...


11

On Linux, you can find the maximum PID value for your system with this: cat /proc/sys/kernel/pid_max This value can also be written using the same file. The maximum for 32 bit systems would be 32768, for 64 bit 4194304: echo 32768 > /proc/sys/kernel/pid_max From man 5 proc: /proc/sys/kernel/pid_max This file (new in Linux 2.5) specifies the ...


11

You cannot kill a <defunct> (zombie) process as it is already dead. The only reason why the system keeps zombie processes is to keep the exit status for the parent to collect. If the parent does not collect the exit status then the zombie processes will stay around forever. The only way to get rid of those zombie processes are by killing the parent. If ...


9

These are indeed the process states. Processes states that ps indicate are: D Uninterruptible sleep (usually IO) R Running or runnable (on run queue) S Interruptible sleep (waiting for an event to complete) T Stopped, either by a job control signal or because it is being traced. W paging (not valid since the 2.6.xx kernel) X dead (should never be seen) Z ...


9

From the ps manpage: Processes marked <defunct> are dead processes (so-called "zombies") that remain because their parent has not destroyed them properly. These processes will be destroyed by init(8) if the parent process exits.


8

Both the kernel and the C runtime do some of the work. Some of the things that the C runtime does which the kernel doesn't do: it runs handlers previously registered with atexit() and it arranges for the integer return value from main() to be returned to the system as if with exit(). Of course in the end the kernel will reap all resources (files, memory) ...


8

The application is connected in two ways: to bash, and to the terminal. The connection to the terminal is that the standard streams (stdin, stdout and stderr) of the application are connected to the terminal. Typical GUI applications don't use stdin or stdout, but they might emit error messages to stderr. The connection to the shell is that if you started ...


7

The top command reads the data from proc, which is provided directly from the kernel. In order to hide processes, you'd have to use code inside the kernel to do the masking. Aside from using a security framework like SELinux and grsecurity (mentioned in the other answers), rootkit-style code is your only remaining option. I say "style" because a "rootkit" ...


6

From the ps man page: -e Select all processes. Identical to -A. Thus, ps -e will display all of the processes. The common options for "give me everything" are ps -ely or ps aux, the latter is the BSD-style. Often, people then pipe this output to grep to search for a process, as in xenoterracide's answer. In order to avoid also seeing ...


6

Linux kernel since 3.3 contains support for hiding processes to other users. It is done by hidepid= and gid= mount options for /proc as described in the corresponding commit and Documentation/filesystems/proc.txt. Debian Wheezy, which will become the next Debian stable release, also includes this feature.


6

I executed tail -n 50 /var/log/message and sadly I no longer have the output but it looked like there had been a serious problem. Lots of memory locations printed in HEX and presumably their contents (incomprehensibly ramblings) on the right. It could have been nearly anything, and the contents of these kernel dumps would be important to knowing ...


5

In the context of a Unix or linux process, the phrase "the stack" can mean two things. First, "the stack" can mean the last-in, first-out records of the calling sequence of the flow of control. When a process executes, main() gets called first. main() might call printf(). Code generated by the compiler writes the address of the format string, and any other ...


5

I believe what you're trying to accomplish is probably best (and AFAIK only) possible combining multiple commands as you're currently doing. With some clever shell scripting and piped data, you could get the output you're looking for. You seem to be up against some tenants of 'The UNIX Philosophy:' Make each program do one thing well. To do a new ...


4

Can you write a small C program? The kill(2) system call does return -1 if your UID doesn't have permission to send a signal to a given process, but errno is set to EPERM in that case, as opposed to ESRCH for a non-existent PID. I'm reasonably certain you could make it portable across Solaris, HP-UX, Linux and the *BSDs. You would have to compile it for ...


4

Your question is a very similar to http://stackoverflow.com/questions/5451206/linux-per-program-firewall-similar-to-windows-and-mac-counterparts There was the --cmd-owner for iptables's owner module, but it was removed because it worked not properly. Now a first beta version of Leopard Flower is available, which solves the problem by a user space daemon. ...


4

That is certainly not trivial task that can't be done in userspace. Fortunately, it is possible to do on Linux, using cgroup mechanizm and its blkio controller. Setting up cgroup is somehow distribution specific as it may already be mounted or even used somewhere. Here's general idea, however (assuming you have proper kernel configuration): mount tmpfs ...


3

There's a standard batch command that does more or less what you're after. More precisely, batch executes the jobs when the system load is not too high, one at a time (so it doesn't do any parallelization). The batch command is part of the at package. echo 'command1 --foo=bar' | batch echo 'command2 "$(wibble)"' | batch at -q b -l # on ...


3

It seems the two main options. Selinux works by putting different people into different security domains and in a sense sand-boxing them so they can't see each-others stuff. This is covered in this question. Since selinux is quickly becoming the de-facto security framework in the Linux world this is probably the direction you should look. The other is ...


3

Create a user that's dedicated to running this application. Give this user write permission on the notRestricted directory and nowhere else. Since you don't mind if the application can read from everywhere, you don't need anything more sophisticated. The application will still be able to write to publicly writable directories: /tmp and /var/tmp on most ...


3

In adition to the cjm's answer, the Single Unix Specification defines a function named vfork(). That function works like fork, except that the forked process has undefined behavior if it does anything other than try calling an exec familly function, or calling _exit(). Thus pretty much the only use with defined behavior is: pid_t ret = vfork(); if(ret == ...


3

ionice from the util-linux does something similar to what you want. It doesn't set absolute IO limits, it sets IO priority and 'niceness' - similar to what nice does for a process' CPU priority. From the man page: ionice - set or get process I/O scheduling class and priority DESCRIPTION This program sets or gets the I/O scheduling class and priority ...


3

You can do this for example with: OLDEST_PID=$(pgrep -o 'DELETE OPERATION_CONTEXT') test $OLDEST_PID && pgrep 'DELETE OPERATION_CONTEXT' | grep -vw $OLDEST_PID | xargs -r kill The first line finds the oldest PID. The second line checks first if $OLDEST_PID contains something. If yes, it list all matching processes, filters the $OLDEST_PID out ...


3

From a user's perspective, it means that the job is paused. It will no longer use any CPU. It will, however, keep using the same amount of RAM. That is why you can bring it back to the foreground with fg and it will continue where it left off. If you kill a job and then restart it, it will start over from scratch.


2

I second the daemontools suggestion, but if you don't like the way DJB's software works (for whatever reason), there's also supervisord. I set up a FreeBSD image a while back that used supervisord to manage nginx and gunicorn, which I used to host some simple WSGI apps, and the whole process was pretty straightforward. If you're doing this for Django, ...


2

I occasionally have to kill -9. However, if this is happening regularly, you should fix the issue that is causing it. Kill -9 means something is way off. In general, I only see this happen when you get yourself into serious memory thrash mode, which means you either need more system memory, or you're giving java too much memory when you start. More ...


2

Manipulating the process table and the memory mappings is always the kernel's job. The kernel acts when some process makes a system call. When a process exits, all of the resources that it uses, including memory, except for the entry in the process table, are deleted − that's what the _exit system call does. Then, when the parent process calls wait or ...


2

Kernel assumes that the parent process is interested in knowing the result of the child process that it forked. First the child process sends to parent SIGCHLD signal. Then parent calls one of the wait functions to retrieve return status from child. If the return status is not retrieved, child remains a zombie. However if the parent process exists before ...



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