|
Softpanorama |
May the source be with you, but remember the KISS principle ;-)
|
| News | Recommended Links | Process Scheduling | Virtual memory management | Virtual Memory | Swap Space Management |
| ps | pgrep | prstat | Humor | Etc |
$ prtconf
System Configuration: Sun Microsystems sun4u
Memory size: 8192 Megabytes
System Peripherals (Software Nodes):
The number of CPUs present in the system can be retrieved from prtdiag command:
System Configuration: Sun Microsystems sun4u Sun Fire V240
System clock frequency: 160 MHZ
Memory size: 8GB
==================================== CPUs ====================================
E$ CPU CPU Temperature
CPU Freq Size Implementation Mask Die Amb. Status Location
--- -------- ---------- --------------------- ----- ---- ---- ------ --------
0 1280 MHz 1MB SUNW,UltraSPARC-IIIi 2.4 - - online MB/P0
1 1280 MHz 1MB SUNW,UltraSPARC-IIIi 2.4 - - online MB/P1
Process Control covers the following topics:
A process is an instance of a running program. It can be any task that has an address space, executes its own piece of code, and has a unique process ID (PID). A process can create another process called a child process Any process that creates the child process is called the parent process. This creation of new processes from existing parent processes is called forking (after the C function called fork()). Most processes in the system are created by fork system calls. A system call causes the current process to be split into two processes: a parent process and a child process. The child process continues to execute on the CPU until it completes. On completion, the child process returns to the system any resources that it used during its execution. While the child process is running, the parent process either waits for the child process to complete or continues to execute. If the parent process continues to execute, it periodically checks for the completion of the child process.
Running multiple processes has an impact on system performance because the processes consume system resources, such as memory and processor time, and some processes may even cause the system to hang. Managing processes becomes important in a multi-user environment such as Solaris. Managing processes involves monitoring the processes, finding the resource usage, finding the parent processes that have created child processes, assigning priority for processes, and terminating processes.
A process undergoes many changes during its lifetime. For example, if a parent process waits for the child process to complete execution, the parent process puts itself in sleep state. Such a change from run state to sleep state is known as a context switch. During its lifetime a process can exist in four states: Init, Run, Sleep, and Zombie. Init is the first genuine user process the system creates. All other processes on the system are created by forking the Init process. If the process is in the Run state, it means that the process is running on the CPU. In the Sleep state, the process waits for a child process to complete, or waits for a resource. Zombie is the phase in which the child process terminates and is not removed from the system until the parent process acknowledges the death of the child process. In this case, the child process is said to be in a Zombie state.
To view the state of a process, use the ps and pgrep commands. The ps command, without any options, lists the process ID (PID), associated terminal (TTY), the cumulative execution time (TIME), and the command that generated the process (CMD)
$ ps PID TTY TIME CMD 6213 pts/5 0:00 sh 6233 pts/5 0:00 ps
The ps el command displays a full listing of all the processes running on the system
$ps -el F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 19 T 0 0 0 0 0 SY ? 0 ? 0:15 sched 8 S 0 1 0 0 40 20 ? 151 ? ? 0:00 init 19 S 0 2 0 0 0 SY ? 0 ? ? 0:00 pageout 19 S 0 3 0 0 0 SY ? 0 ? ? 10:43 fsflush 8 S 0 314 1 0 40 20 ? 222 ? ? 0:00 sac 8 S 0 229 1 0 40 20 ? 130 ? ? 0:00 utmpd 8 S 0 180 1 0 40 20 ? 596 ? ? 0:01 automoun 8 S 0 52 1 0 40 20 ? 283 ? ? 0:00 sysevent 8 S 0 59 1 0 40 20 ? 338 ? ? 0:01 picld 8 S 0 111 1 0 40 20 ? 208 ? ? 0:02 in.route 8 S 0 118 1 0 40 20 ? 242 ? ? 0:00 in.ndpd 8 S 0 156 1 0 40 20 ? 311 ? ? 0:00 inetd 8 S 0 188 1 0 40 20 ? 417 ? ? 0:00 syslogd 8 S 0 133 1 0 40 20 ? 308 ? ? 0:00 rpcbind 8 S 0 170 1 0 40 20 ? 289 ? ? 0:00 lockd 8 S 25 420 1 0 40 20 ? 535 ? ? 0:00 sendmail 8 S 1 169 1 0 40 20 ? 318 ? ? 0:00 statd 8 S 0 218 1 0 40 20 ? 176 ? ? 0:00 powerd 8 S 0 195 1 0 40 20 ? 284 ? ? 0:00 cron 8 S 0 210 1 0 40 20 ? 387 ? ? 0:01 nscd 8 S 0 4972 4971 0 80 30 ? 520 ? ? 0:00 dtscreen
F Flags associated with the process.
S The state of the process.
UID The user ID.
PID Each process has an associated ID. You can use this ID to determine the state of a specific process.
PPID The parent process ID.
C Processor utilization.
PRI The set scheduling parameters for a process.
NI The nice value displays the assigned priority to the process.
NOTE
Is state is Z this is a zombie process. Pretty common for Websphere and other semi-debugged applications. For further information on the fields, view man pages for the ps command.
ADDR The memory address of the process.
SZ The total number of pages in the process, in virtual memory, including all mapped files and devices.
WCHAN The address of an event for which the process is sleeping.
TTY The terminal from which the process originated. System processes have a ? in this field.
TIME The processor utilization time.
CMD The command that has spawned the process.
The pgrep command displays a list of the process IDs of active processes on the system that match the pattern specified in the command line. The pgrep command functionally combines the ps command with the grep command. The syntax for the pgrep command is as follows:
pgrep [-option] pattern
|
Options |
Description |
|---|---|
| - l | long listings (name of the profess and its PID) |
| -g pgrplist | Matches the processes with the process group ID. |
|
-G gidlist |
Matches the active processes with the group ID(s) specified in the command line. For example, if you are searching for processes running with the group ID sysman, specify the command pgrep G sysman. |
|
-d delim |
Specifies a delimiter for separating PIDs. |
-n |
Matches the most recent process. |
|
-P ppidlist |
The processes are matched with the parent process ID in the listing. |
|
-s sidlist |
The processes are matched with the session ID in the list. |
|
-t termlist |
Matches the terminal on which the process is running. |
|
-u euidlist |
Matches processes with the effective used ID in the list. The effective uid is the uid of the executable file when the SUID of the file is set. |
|
-U uidlist |
Matches processes with the real uid in the list. The real uid is the uid that the user uses when starting a task or a process. |
|
-v |
Matches all processes except those that meet the specified criteria in the command line. |
|
-f |
Matches pattern against full arguments rather than the name of the executable file. |
|
-x |
Matches the processes that exactly match the specified pattern. |
The following example displays the process ID for the process sh:
$ pgrep sh 3 8027 307 765 762 6488 7970 8147 8150
The following command displays the process ID of all those processes matching the in pattern:
$ pgrep in* 1 59 111 118 156
$ pgrep -l in
1 init
111 in.routed
118 in.ndpd
156 inetd
133 rpcbind
The following command displays the processes owned by user James:
$ pgrep -u james 1459 1464 $
You can combine options. In the following example, both the l and the u options are used together with the pgrep command to display the names of all the processes run by user James, along with his process ID.
$ pgrep -l -u james 1459 sh 1464 csh
The -d option is used to specify a delimiter for separating PIDs when more than one process ID is tested in the output of the pgrep command. The following example uses delimiters for the listed processes for the user James.
$ pgrep d";" u james 951; 1042; 1051
NOTE
You can specify more than one user ID by using a comma (,) as a field separator.
Use the kill and the pkill commands to terminate a process. These commands send the appropriate signal to the intended processes to terminate them. A signal notifies a process that an event has occurred. The event could be raised because of issues with the hardware or software, a change in the system date, a change in the system state, and so forth. An inter-process communication takes place because one process sends a signal to another process to instruct the latter to act in a certain manner.
The kill command enables the user to kill the process. Only a superuser can kill a process owned by others. The kill command sends a signal to a process, which is used to terminate it. The syntax for the kill command is
# kill <signal> <process ID>
To kill a process, you should know its process ID. To find the process ID, you may use the following command:
ps ef | grep <process name>
Even though many signals are available, signal 15 and 9 are the ones that are generally used with the kill command. Signal 15 sends the SIGTERM signal to the specified process. The SIGTERM signal is referred to as a "gentle signal," which allows the process to rectify itself. Unlike the SIGTERM signal, the SIGKILL (signal 9) is a "sure kill" signal. The processes that are not responding to the SIGTERM signal can be killed with the SIGKILL signal.
Some processes still exist even after a SIGTERM signal. A process might still be alive for the following reasons:
The process is hung.
The process is waiting for some other process to execute.
The process is in the state of Zombie. Note that the process in the Zombie state is not alive and does not use any resources or accomplish any work. However, it is not allowed to die until the parent process acknowledges the exit call.
The process is waiting for some unavailable resources. The resources may be network resources or access to a device.
NOTE
The kill command, without any signal, issues the SIGTERM (signal 15), by default.
The following syntax sends signal 15 to the process with a process ID of 1305.
# kill 1305
The following example illustrates using the kill command to send signal 9 to kill three different processes:
$ kill 9 3012 3019 3510 $ 3510 killed $ 3019 killed $ 3012 killed
Any number preceded by a minus (-) sign in the <PID> field represents a process group ID. In the following example, the 9 signal is sent to the process with PID 1039 and all the processes with the process group 117.
#kill 9 1039 117
The pkill command terminates the displayed processes that match the pattern specified. The pattern is a regular expression that is used to specify processes based on the program name. The pkill command sends the SIGTERM (signal 15) to the matching processes. The command syntax for the pkill command is as follows:
pkill [-option] pattern.
For example, to terminate the most recently created Admintool, type the following:
# pkill n admintool
The pkill command takes any signal other than signal 15 (SIGKILL). The following command sends a SIGKILL signal to the processes owned by user Romando:
# pkill 9 u romando
CDE provides a Process Manager utility to manage processes. You can use Process Manager to change the priority of the processes and to kill them. To kill a process, select a process in the window and click the Kill option in the Process menu. You also can use the Ctrl+C keyboard combination to kill the selected process.
You also can use Process Manager to send signals to a process. For example, to send a sure kill signal to a process, perform the following steps:
Process Manager enables you to sort the processes by any of the displayed fields. For example, you click the CPU% option to sort the processes by the amount of CPU time they consume.
Process Manager also enables you to save a list of processes to a log file. It offers a filter option that you use to display all process entries that match the specified criterion.
The Process Manager presents a list of all processes on a system. The following are the fields displayed in the Process Manager window:
ID The process ID
Name The name of the process
Owner The owner of the process
CPU% The CPU time consumed
RAM The physical memory used
Size The total virtual memory size of the process, including all mapped files and devices.
Started The date the process was started
Parent The parent process ID
Command The full command string
With the Process Manager, you can sort the processes on the system on the basis of any of the items in the above list. For example, if you click the CPU% option, the process list is displayed on the basis of the CPU usage.
To save a sample of the process listing in a log file, open the Sample submenu of the Process Manager and select the Log File option.
To save a log file of a single sample, choose Sample, Save. The Save As window is displayed. Specify the log file location and click Save, which creates the process log.
With the Process Manager, filter processes that match specified text. Type some text in the Filter text box in the Process Manager and press Return.
Empty the filter text box and press Enter to redisplay all the processes on the system.
To kill a process, select the process from the listing and select Process, Kill. You also send signals to a process, similar to the signals sent from the command line. For example, to send signal 9 (sure kill) for killing a process, select the process from the Process Manager, click the Signal option, which displays an Action:Signal window where you specify 9 in the Signal text box and press Enter to kill the process.
Copyright © 1996-2008 by Dr. Nikolai Bezroukov. www.softpanorama.org was created as a service to the UN Sustainable Development Networking Programme (SDNP) in the author free time. Submit comments This document is an industrial compilation designed and created exclusively for educational use and is placed under the copyright of the Open Content License(OPL). Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.
Standard disclaimer: The statements, views and opinions presented on this web page are those of the author and are not endorsed by, nor do they necessarily reflect, the opinions of the author present and former employers, SDNP or any other organization the author may be associated with. We do not warrant the correctness of the information provided or its fitness for any purpose.
Last modified: February 28, 2008