Linux Basics (tutorial) #13

Discuss everything about Linux here!

Moderator: Community Moderator

Post Reply
User avatar
MrNiitriiX
Premium Uploader
Premium Uploader
Posts: 2197
Joined: 19 Apr 2010, 14:52
Location: between space and time
Has thanked: 24 times
Been thanked: 164 times

Linux Basics (tutorial) #13

Post by MrNiitriiX »

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.

LINKS TO THE OTHER TUTORIALS


Leason 1: Living in a shell
Leason 2: Root and Other Users
Leason 3: Virtual Consoles
Leason 4: Logoff and Shutdown
Leason 5: Choosing a Shell
Leason 6: The Command Prompt
Leason 7: Wildcards
Leason 8: Command History and Editing
Leason 9: Aliases
Leason 10: Redirection
Leason 11: Pipelines
Leason 12: Processes
Leason 13: Stopping a Program
Leason 14: Environment Variables
Leason 15: Help!
Last edited by MrNiitriiX on 31 Jul 2010, 13:03, edited 1 time in total.
"Injustice anywhere is a threat to justice everywhere." - Martin Luther King
Image
Upload List
Post Reply

Return to “Everything Linux”