Indiana University


ComputerScience






 Home

 Contacts

 Courses

 Academics

 Careers

 Research

 People

 Calendar

 Resources

 Facilities
   FAQ
   System Notices
   Help
   Hardware
   Software
   Network
   Policies
   CSG Staff
   Lindley Hall

 Hiring

CSG FAQ

Q: How do I see the processes I have running on a unix machine and, optionally, how do I kill them?

The normal command used to see what processes you have running on a unix system (ie. Solaris, Linux, Irix, etc.) is ps. The problem is that, by default, the ps command typically does not show you all of your processes so it may be confusing. If you run ps with no arguments, it will usually only show you the processes that you own and that have what is called the same "controlling terminal" as your current shell. If you are logged into a GUI on the console (such as CDE, Gnome, or KDE), you have multiple logins to a machine remotely, or you have processes running in the background, then just running ps will only show you a subset of the processes you actually have running. To see all of your processes with ps you have to use the proper command line flags or, optionally, some other program.

This is further complicated by the fact that the various process display and control programs may behave differently on different variants of unix. For example, the ps command has slightly different usage across platforms which can be very confusing.

Here is a brief listing of some of the common ways you can see the process you have running.

  • Arguments to ps - There are lots of command line arguments to ps and it can get pretty tricky to understand them all (see the ps manual page by running "man ps" for all the gory details). However, here are a couple examples of common arguments. You will need to replace username with your own username in the examples:

    ps  -fe   Display a full listing of all the processes currently running
    ps  -fu username
    Display a full listing of all the processes owned by username

    Also note that there are two different versions of ps on the Suns: /usr/bin/ps (with SYSV Unix syntax) and /usr/ucb/ps (with BSD Unix syntax). The default is /usr/bin/ps but, depending on how you customize your PATH environment variable, you may be using /usr/ucb/ps. Just run "which ps" to see which one you are using. If you are using /usr/ucb/ps instead of /usr/bin/ps, then you will have to run "ps -augx" to display all processes.

  • top - The top command is a great tool for displaying processes. Just run top and it will show you a periodically updating list of the processes running on the system. The listing will be ordered by CPU usage by default and will display processes from all users, not just you. Just type 'u', followed by your username, to display only the processes you own. Type 'h' to see the help page and type 'q' to quit.

  • ptree (Solaris only) and pstree (linux only) - The ptree command under solaris and the pstree command under linux display processes in a tree showing the parent/child relationship between processes. Run one of the following commands:

    ptree username   (Solaris)
    pstree username(Linux)

    to display the processes owned by the named user.

Now that you have been able to find the processes you have running, you may want to kill a process. The normal unix command for killing processes is kill but, again, things aren't always as easy as we would like. Once you locate the process using ps or top, you will be able to determine the Process ID, or PID, of the process and kill it by just running:

kill PID

By default, kill sends what is called the SIGTERM signal to the process to tell it to terminate. However, it is possible for the process to ignore this request so this may not actually kill the process. If this fails to kill the process, then you will have to send the process the KILL signal which is a signal the process cannot ignore. You can do this by running:

kill -KILL PID

In addition to the kill command, there are a number of other ways to kill a process that you may find more convenient. These include the following: (note that all of these might not be available on all flavors of unix)

  • killpid - This is a handy little script that tries to kill a process using the default TERM signal and then, if that doesn't kill it, tries using KILL. For example, to kill PID 12345 just run

    killpid 12345

  • killbyname - This is another handy script that tries to find a named process and kill it. For example, if you had a program called example1 running, you could kill it with:

    killbyname example1

  • top - It is possible to kill processes from within top (mentioned above). While viewing the top output, just hit 'k', followed by the PID of the process you wish to kill. Like ps, top will send the TERM signal to the process which may or may not actually kill it. To send the KILL signal, hit 'k' followed by something like '-KILL 12345'.

  • killme - The killme script finds and kills every process you have running on a machine. You can just run:

    killme

    to kill all your processes. Use with caution since it will kill everything owned by you, which will also log you out.




See an error in this FAQ entry? Please report it.

[Return to the FAQ index]









Valid HTML 4.01!