Search
Enter Keywords:
Home
How to Kill a Program on a Remote Macintosh PDF Print E-mail
User Rating: / 1
PoorBest 
Written by Michael Salsbury   
Monday, 11 July 2005

Like any UNIX based operating system, OS X has a pretty versatile command line. You can do quite a lot with it.  For example, I've written scripts that backup an OS X system to a server.  Using the SSH capability, I can connect to a Macintosh in another building and run that script, causing the machine to run a backup any time I need it to.  Sometimes, as a system administrator, I need to deal with programs that are hanging on the user's Mac and causing problems.  Fortunately, I can kill a program like that without ever having to leave my desk.  Here's how...

First, you have to have already setup an environment where you can remotely connect to the other Macintosh via the command line.  If you haven't done that, or don't know how, here's all it takes:

  1. Go to the Apple menu and choose System Preferences.
  2. Click the "Show All" icon.
  3. Under "Internet & Network" click "Sharing".
  4. Place a checkmark in the "Remote Login" box.
  5. Close the System Preferences Window. You're done!

Now, to connect to a computer setup as above, do the following:

  1. Launch a Terminal window.
  2. Enter the command "ssh <admin>@<machinename>" where "<admin>" is the short name of an administrator account on the remote computer and "<machinename>" is the remote computer's name or IP address.
  3. If you're prompted about an "RSA key", just enter "yes" at the prompt to continue connecting.
  4. When the "Password:" prompt appears, enter the password for the administrator account you specified in your SSH command.
  5. When the next command prompt appears, you are connected to the remote computer and are issuing commands that are running on THAT computer, not yours.

Let's assume that a user has called us to tell us that Internet Explorer seems to be locked up on their Macintosh.  We'd like to terminate Internet Explorer for them so that they can save the data in their other programs and reboot the Mac (just to be safe).  We connect to their computer via SSH and get to the command line.  Now we need to find Internet Explorer in their process list.  To do that, we issue the command:

ps -aux

This results in the Macintosh displaying a list of running processes that resembles the following:

USER     PID %CPU %MEM      VSZ    RSS  TT  STAT STARTED      TIME COMMAND
root       1   0.0  0.0    18072    132  ??  Ss   28Jun05   0:00.09 /sbin/init
root       2   0.0  0.0    18608    188  ??  Ss   28Jun05   0:36.65 /sbin/mach_init
root      78   0.0  0.0    18092    184  ??  Ss   28Jun05   0:05.11 /usr/sbin/syslogd -s -m 0
.
.
.
user   8735   0.0  1.2   179316  18452  ??  S     1:23PM   0:09.86 /Applications/Internet Explorer.app/Contents/MacOS/Internet Explorer /Applications/Internet Explorer.app/Contents/MacO
admin   8736   0.0  0.2   150340   2736  ??  S     1:23PM   0:00.26 /Applications/Timbuktu Pro/Timbuktu Pro.app/Contents/SharedSupport/Timbuktu Host Menu.app/Contents/MacOS/Timbuktu Host
admin   8744   0.0  0.2   151164   3040  ??  S     1:23PM   0:00.35 /Library/Application Support/Norton Solutions Support/SymQuickMenu/SymQuickMenu.app/Contents/MacOS/SymQuickMenu -psn_0
root    8745   0.0  0.1    28548   1496  ??  S     1:23PM   0:00.16 /Library/Application Support/Norton Solutions Support/Norton AntiVirus/DiskMountNotify.app/Contents/MacOS/DiskMountNot
admin   8746   0.0  0.1    98788   1300  ??  S     1:23PM   0:00.12 /Library/Application Support/Norton Solutions Support/Norton AntiVirus/ScanNotification.app/Contents/MacOS/ScanNotific
admin   8747   0.0  0.1    98676   1216  ??  S     1:23PM   0:00.15 /Library/Application Support/Norton Solutions Support/Scheduler/SymSecondaryLaunch.app/Contents/MacOS/SymSecondaryLaun
root    8837   0.0  0.3    30740   5488  ??  Ss    1:31PM   0:00.38 /usr/sbin/sshd -i


Notice the line which reads:

user   8735   0.0  1.2   179316  18452  ??  S     1:23PM   0:09.86 /Applications/Internet Explorer.app/Contents/MacOS/Internet Explorer /Applications/Internet Explorer.app/Contents/MacO

This tells us that Internet Explorer has the process ID number 8735 associated with it.  Now all we need to do is tell the user's machine to terminate that process.  To do that, we issue the command:

kill 8735

This sends a "TERM" signal to the process, which it may ignore and not quit.  If it still shows in the list after sending this signal, issuing the following command will force the termination:

kill -9 8735

Similarly, if you know the process name (in the example above, that's "Internet Explorer.app") you can kill the process by its name, such as:

killall "Internet Explorer.app"

Above would kill all running instances of Internet Explorer.

(Thanks to "kainjow" and "lurk" on macosx.com for filling in some gaps in my knowledge of this capability after I posted a link to this article on the OS X forum! :-) )