Musician, Ruby on Rails Entusiast, Composer, Programmer and Lover of Hot Sauce

Working With Server Processes

Posted: July 27th, 2009 | Author: mindtonic | Filed under: Development, Unix | Tags: , | No Comments »

A simple little entry, I know, but a powerful tool to use and remember!

Display full information about each of the processes currently running.:

ps -ef

Output:
UID PID PPID C STIME TTY TIME CMD
hope 29197 18961 0 Sep27 ? 00:00:06 sshd: hope@pts/87
hope 32097 29197 0 Sep27 pts/87 00:00:00 -csh
hope 7209 32097 0 12:17 pts/87 00:00:00 ps -ef

To see just Ruby processes:

ps -ef | grep ruby

How to Kill Processes for a User

I had a BackgrounDRb process that just wouldn’t give it up, for a month, really! When all else failed, this worked:

kill -9 `ps -u username | grep -v PID | awk '{ printf ("%s ", $1); }'`

Replace username with the actual user name. Of course you should only use the -9 option when you really have to.

The New Way

Instead of going through all of that, you can simply use the pkill command if you already know the process name or part of it.

$ pkill packet_worker_runner

It’s as simple as that. You should note that pkill will kill all processes matching the search text, in this case backgroundrb processes which can be identified by the packet_worker_runner process name.

If you want to see what process names are matched before using the pkill command, you can use the ps command as described above.

$ ps -ef | grep packet_worker_runner