Linux Classes
Share This With a Friend  
LINUX CLASSES - LINUX BASICS

How Do I Stop a Running Program?

Stop That Task!

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

[ RETURN TO INDEX ]


   

Comments - most recent first
(Please feel free to answer questions posted by others!)

kk     (05 Feb 2013, 07:11)
there are two simple commands one is to view the background running jobs the is #bg

and the second one is #fg to get the improperly closed job to foreground and then close it.

NOTE: never use ctrl+z key because the job will not be terminated but it goes and runes in background.
Angelo     (05 Dec 2011, 07:51)
To use this linux you don't need a computer, usually a car is enough. Since when there is more than ONE Internet? GEEEEEEEEEEEEEEZZZZZZZZZZZZZZ
husong     (04 Dec 2011, 22:15)
Do I need to make purchase a computer for using this Linux? Will I go to internets?
Linux Master     (09 Nov 2011, 19:45)
Yeah you are right, I think they are stupids.
Angelo     (07 Oct 2011, 21:23)
It seems that people commenting here are either stupid or spammers
renuka     (29 Aug 2011, 01:18)
hi
how to start STAF(software testing automation framework) automatically when machine is started in Linux?
please give me explanation?
reply me soon...:)
elvis oduong     (23 Feb 2011, 08:08)
Linux is not commonly used here and should i go for it,i would be operating in my own world. what plans do u have to popularize it?
dave     (08 Aug 2010, 11:46)
I tend to use:
ps -A | grep (offending process) to locate what I know is the cause. For example if firefox is hanging I do:

ps -A | grep firefox.

That points me right to the offending process.

I welcome your comments. However... I am puzzled by many people who say "Please send me the Linux tutorial." This website *is* your Linux Tutorial! Read everything here, learn all you can, ask questions if you like. But don't ask me to send what you already have. :-)

NO SPAM! If you post garbage, it will be deleted, and you will be banned.
*Name:
Email:
Notify me about new comments on this page
Hide my email
*Text:
 
 


Ask Bob Rankin - Free Tech Support


Copyright © by - Privacy Policy
All rights reserved - Redistribution is allowed only with permission.