|Using The ps And top Commands
The Unix commands covered in this section: ps, grep, top
The basic unit of execution in UNIX (and many other operating systems) is called a process. In the "Redirecting input/output" section of the tutorial, you were asked to think of a process as a program you run from the shell. This is not far from the truth in most cases. What you think of as a program often consists of a single process. Your login shell and all the commands you've used in this tutorial run as single processes. In some cases, however, what you think of as a single program (e.g., a web or database server) actually consists of multiple processes communicating with each other. In this section, you will learn how to list the processes currently running on the system using the ps and top commands. In the next section, you'll learn how to manipulate processes.
Use the ps command to see the processes associated with the current
Until you've learned how to run processes in the background, the output of ps is not terribly interesting, since there are no other processes besides the shell itself to display. However, by adding some options to ps, we can make things a bit more interesting. The "-e" option tells ps to list all processes running on the system, not just those associated with the current shell. The "-f" option creates a full listing, which includes more information about each process.
Use ps -ef to get a full listing of all processes on the system. Since there are generally many processes to be listed, you'll want to pipe the output into a pager, such as more.
% ps -ef | more
In some cases, you may want to restrict the listing to a few processes -- perhaps all processes belonging to a given user, or all occurrences of a certain program. You can use the grep command to do the filtering. It prints lines matching a specified pattern in its input while discarding lines that don't match.
Create a pipeline using ps -ef to get a full listing of all processes and grep look for all occurrences of the pine e-mail program.
ps -ef | grep pine
The top program also lists processes, but adds the ability to sort by various criteria (CPU utilization by default) and provides a continuously updated display. It also gives a useful summary of the status of the system, including memory and CPU utilization.
Use top to display the processes using the most CPU time. To exit top when you're done, press 'q'.
THR PRI NICE SIZE RES STATE TIME
Note that top also displays additional fields not shown by ps, including the scheduling priority and "nice" level.
Have a Unix Problem
Return to : - Unix System Administration Hints and Tips
(c) www.gotothings.com All material on this site is