Skip to Main Content
Learning Unix for Mac OS X, Second Edition
book

Learning Unix for Mac OS X, Second Edition

by Brian Jepson, Dave Taylor
December 2002
Beginner content levelBeginner
160 pages
4h 22m
English
O'Reilly Media, Inc.
Content preview from Learning Unix for Mac OS X, Second Edition

Canceling a Process

You may decide that you shouldn’t have put a process in the background or the process is taking too long to execute. You can cancel a background process if you know its process ID.

kill

The kill command terminates a process. This has the same result as using the Finder’s Force Quit command. The kill command’s format is:

kill PID(s)

kill terminates the designated process IDs (shown under the PID heading in the ps listing). If you do not know the process ID, do a ps first to display the status of your processes.

In the following example, the sleep n command simply causes a process to “go to sleep” for n seconds. We enter two commands, sleep and who, on the same line, as a background process.

% (sleep 60; who)&
[1] 543
% ps
  PID  TT  STAT      TIME COMMAND
  310 std  S      0:00.52 -tcsh (tcsh)
  543 std  S      0:00.00 -tcsh (tcsh)
  544 std  S      0:00.01 sleep 60
  545 std  R+     0:00.00 ps
  459  p2  S+     0:00.25 -tcsh (tcsh)
% kill 544
# Terminated
taylor   console  Feb  6 08:02 
taylor   ttyp1    Feb  6 08:30 
taylor   ttyp2    Feb  6 08:32 
  
[1]    Done                          ( sleep 60; who )

We decided that 60 seconds was too long to wait for the output of who. The ps listing showed that sleep had the process ID number 544, so we use this PID to kill the sleep process. You should see a message like “terminated” or “killed”; if you don’t, use another ps command to be sure the process has been killed.

In our example, the who program is now executed immediately, as it is no longer waiting on sleep; it lists the users logged into the system. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mac OS X for Absolute Beginners

Mac OS X for Absolute Beginners

Wallace Wang
JMP Connections

JMP Connections

John Wubbel
Using csh & tcsh

Using csh & tcsh

Paul DuBois

Publisher Resources

ISBN: 0596004702Catalog PageErrata