Finding Out Process Status One of the most important Unix commands is ps With

Finding out process status one of the most important

This preview shows page 7 - 12 out of 18 pages.

6. Finding Out Process StatusOne of the most important Unix commands is ps. With this command you can find outvarious information about processes running on your machine. Without options, thiscommand displays the list of processes running under the current shell. Example:hong:~ $psPID TTYTIME CMD31587 pts/000:00:00 bash31601pts/000:00:00 pshong:~ $Here, PIDis the process ID, a unique integer for each process. TTYtells you the terminal in which the process runs. The command ttywill display the name of your terminal. TIMEtells you the CPU time used by the process. CMDshows the command that was used to invoke the process.ps has many options. One often used is-f. With this option more information will be displayed:
Image of page 7
hong:~ $ps -f UID PID PPID C STIME TTY xie 31587 31586 0 21:43 pts/0 xie 31604 31587 0 21:52 pts/0 hong:~ $ TIME CMD 00:00:00 -bash 00:00:00 ps -f
Image of page 8
In the above example, UID shows the user who created the process. PPID is the parent PID. STIME is the starting time of the process. Another useful option is -l : hong:~ $ps -l F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 000 S 1002 31587 31586 0 72 0 - 502 wait4 pts/0 00:00:00 bash 000 R 1002 31611 31587 0 76 0 - 795 - pts/0 00:00:00 ps hong:~ $ In this example, S tells you the process state: S for sleep, R for running, T for stopped, Z for zombie/defunct processes. UID shows you the User ID number of the user who created the process. In Unix, each user has a username (such as xie in above example) and an integer uid (such as 1002 for user xie , and 0 for root). PRI tells you the scheduling priority of the process. It is between 0 (high) and 127 (low). NI is the nice value , which is used to change the priority indirectly. The nice value is between -20 (a greater chance of a higher priority) and 19 (a greater chance of lower priority). To display all processes, use option -e . You can combine different options together too: hong:~ $ps –el
Image of page 9
Image of page 10
You will see that some processes are run by the root and are hence not associated with any terminal ( TTY=? ). Some of these are daemons, or servers. Another option -H displays the process hierarchy, i.e. parent-child relationship. For example: [email protected]:~$ ps -efH | grep S900432D S900432D 32628 32625 0 21:19 ? 00:00:00 sshd: [email protected]/0 S900432D 32629 32628 0 21:19 pts/0 00:00:00 -bash S900432D 958 32629 0 22:20 pts/0 00:00:00 ps -efH S900432D 959 32629 0 22:20 pts/0 00:00:00 grep S900432D [email protected]:~$ The above command line consists of two commands ps -efH and grep S900432D connected by a pipe ("|"), which links the standard output of the first command with the standard input of the second command. The command grep displays those input lines that contain the string "S900432D". The output in the above command line shows all processes started by the user "S900432D". It also reveals the hierarchical structures of these processes. Try all commands used in this question and try to understand the output with the help of manual page of the ps command. 7. Killing Processes You can kill any process you own by sending the signal SIGKILL (signal 9). Firstly you need to find out the PID of the process you want to kill, then use the command: kill -9 pid Note you cannot kill a process that is owned by other users. However, root can kill any process.
Image of page 11
Image of page 12

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture