Killing programs softly

OSX has a command in the Apple menu called “Force Quit…“. All this does when you select a program, is kill the process ID. Confused?

Okay, so when you run a program, the operating system (e.g. OSX) associates a process-id (PID) with the program, basically so it can keep track of it. Sometimes when you run a program, and it hangs for some reason (i.e. stops working, but does not quit) it needs to be terminated. Ctrl-C may not work, so the easiest way to kill the program is to run the command ps, which returns the status of the current running processes. For example, you might get something like this:

>ps
 PID TTY        TIME CMD
3004 ttys000 0:00.37 a.out

By typing kill -9 3004, the PID 3004 is terminated, meaning the program a.out is terminated, gone, vamoosed! Kill works in the following way:

kill PID_to_terminate

This basically sends the signal TERM to the process, telling it to terminate nicely, cleaning up anything it needs to. If this doesn’t work – and sometimes sticky processes can be somewhat stubborn, a more intensive KILL signal can be used:

kill -KILL PID_to_terminate

But this time, things aren’t as pleasant, and the signal is sent to the kernel instead of the process itself. The kernel will shutdown the process. The -KILL is equivalent to -9.

Now ps won’t tell you everything. It won’t show all the programs running. For that you can use top. The top chunk of information shows a myriad of system statistics – system load, no. of running processes, no. of sleeping processes, CPU usage, etc. The bottom portion shows the actual processes running, or in stasis (a.k.a. idle). Probably more information than the average user needs, but you never know.

top

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s