How Do I Stop a Running Program?
Although it's unfortunate, some tasks are unruly and must be killed. If you accidentally entered the (fictitious) command
seek_and_destroy &you'd have a background task doing potentially nasty things. Pressing the ctrl-C key would have no effect, since it can terminate only a foreground task. Before this rogue eats your system alive, issue the ps -f command to find out the process ID (PID) of the seek_and_destroy task:
ps -f
UID PID PPID STIME TTY TIME COMD
hermie 24 1 00:35:28 tty1 0:01 bash
hermie 1704 24 00:36:39 tty1 0:00 seek_and_destroy
Note that the offender has a PID of 1704 and then quickly issue the command
kill 1704
to terminate the background task.
You can terminate any active task with the kill command, which sends a "terminate gracefully" signal to the running task that allows it to do any necessary cleanup, close files, and so on before giving up the ghost. Occasionally, though , a task will not respond to the kill command, either because a program has become disabled or is coded specifically to ignore it. Time for the heavy artillery. Adding the -9 flag to the kill command, as i n
kill -9 1704
basically sends the "die you gravy-sucking pig" signal to the running task and forces it to shut down immediately without any chance to do cleanup. Use this flag only as a last resort, since it could cause work in progress (by the soon- to-be-killed task) to be lost.
For more information on the kill command, see the kill manual.
Previous Lesson: Processes
Next Lesson: Environment Variables
Comments - most recent first
|
| ||
![]() |
All rights reserved - Redistribution is allowed only with permission.