The ps Command


The ps Command

The ps command will list your current processes. You can also run processes with this command. The ps command is helpful because once you start using the background capabilities of Unix, at some point you will need to find out what all you have running. After all, if you continue to aimlessly start process after process, you may find that you have a lot more running on your Unix system than you want. In Unix, you can run the ps command at the shell prompt. Once you do this, you will see something similar to the following:

 >ps   PID TTY STAT  TIME COMMAND  8832  p1 R    0:00 ps 30675  p1 S    0:00 -bash (Output removed) 

If you run ps and see this result, you are looking at a list of all the commands you currently have running. Don't be alarmed if you do not see the same output as that listed here; the ps command generates slightly different results in different versions of Unix and Linux. Nonetheless, the same information is generally provided in each version.

How, then, do you interpret this output? From left to right, the columns indicate the system process ID (PID), the controlling terminal, the status of the process (running, sleeping, and so on), and the process itself. Some versions won't show you the status, but this varies depending on what Unix distro you are using. In most cases, however, typing the ps command will provide you with the most important things you need to know, which are the PID and the processes in use.

Where Are the Processes? In our example, we saw only a couple of processes running. Could those really be all the processes? There aren't any more than that? There have to be, right?

Yes, there are other processes running, and to see them all, you have to know the proper option for the ps command. If you just enter ps, you will see a list of all the processes you own, but to see a listing of the processes owned by all users, you need to enter either ps ax or ps ef.


In addition to understanding the ps command, you should also understand how to stop or kill a process.



    SAMS Teach Yourself Unix in 10 Minutes
    Sams Teach Yourself Unix in 10 Minutes (2nd Edition)
    ISBN: 0672327643
    EAN: 2147483647
    Year: 2005
    Pages: 170

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