Deleting Processes with kill


Deleting Processes with kill

In addition to suspending jobs and running them in the foreground and background, you can also choose to just delete them completely. For example, you might realize midway through a job that you goofed and need to redo it. Or perhaps you've accessed and suspended a man page and no longer need to reference it.

Using kill, you can delete essentially any process running or suspended on the Unix system. As Code Listing 9.14 shows, you delete a process by first listing the processes, then using the kill command.

Code Listing 9.14. Using kill plus the PID number, you can delete practically any process running or suspended on the system.

$ ps a f  PID TTY STAT TIME COMMAND 15911 p1 S 0:00 /bin/login -h calvin   raycomm.com -p 15914 p1 S 0:01 \_ -bash 16216 p1 T 0:00    \_ telnet 16217 p1 T 0:00    \_ lynx http://www.raycomm.com/ $ kill -9 16217 $ ps a f   PID TTY STAT TIME COMMAND 15911 p1 S 0:00 /bin/login -h calvin   raycomm.com -p 15914 p1 S 0:01 \_ -bash 16216 p1 T 0:00    \_ telnet $ 

To Kill a Job with kill:

1.

jobs

At the shell prompt, type jobs, then note the number or name of the job you want to kill.

2.

kill %ftp

In most shells, you can kill jobs with kill followed by % and the job number or command namefor example, you could kill an ftp job with a job number of 1 using kill %ftp or kill %1. If your shell doesn't cooperate, read on.

To delete a process with kill:

1.

ps

At the shell prompt, type ps to see the list of all your current jobs (Code Listing 9.14). Note the PID (process identification) number of the process you want to delete.

2.

kill 16217

Type kill followed by the PID number of the job you're deleting.

Tips

  • Occasionally, you'll use kill and find that the process just keeps going. Try kill -9 followed by the PID number to delete the process.

  • Be careful not to kill your current shell process, or you'll abruptly find your connection broken. Doing so would be like sawing off the branch you're sitting on.

  • Many newer Unix systems allow you to use pkill to kill processes by name, not number. For example, you might use pkill ftp to kill a suspended ftp session.





Unix(c) Visual Quickstart Guide
UNIX, Third Edition
ISBN: 0321442458
EAN: 2147483647
Year: 2006
Pages: 251

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net