Process Management

Process: Every program in Solaris runs as a process and there is a unique PID attached with each process. The process started/run by OS is called Daemon. It runs in background and provides services.

Each process has a PID, UID and GID associated with it. UID indicates the user who owns the process and GID denotes the group to which owner belongs to.

When a process creates another process, then the new process is called Child Process and old one is called Parent Process.

Viewing Process: 

ps command: It is used to view process and is discussed below.
Syntax: ps options

Few options are discussed below:
Option
Description
-ePrints info about every process on the system including PID, TTY(terminal identifier), TIme & CMD
-fFull verbose listing which includes UIDm parent PID, process start time(STIME)


Example: 
#ps -ef | more
     UID   PID  PPID   C    STIME TTY         TIME CMD
    root     0     0          0   Jun 02      ?           2:18 sched
    root     1     0          0   Jun 02      ?           1:47 /sbin/init
    root     2     0          0   Jun 02      ?           0:13 pageout
    root     3     0          0   Jun 02      ?         110:25 fsflush
  daemon   140      1   0   Jun 02      ?           0:15 /usr/lib/crypto/kcfd
    root     7     1          0   Jun 02      ?           0:28 /lib/svc/bin/svc.startd
--More--

Now let us understand the above output column wise :

Column
Description
UIDUser Name of the process owner 
PID Process ID
PPIDParent Process ID
CThe CPU usage for scheduling
STIMEProcess start time
TTYThe controlling terminal for process. For daemons '?' is displayed as it is started without any terminal.
TIMEThe cumulative execution time for the process.
CMDThe command name, options, arguments

We can also search specific process using ps and grep command. For Example, if we want to search for nfsd process, we using the following command :

-sh-3.00$ ps -ef | grep nfsd
  daemon  2127     1   0   Jul 06 ?           0:00 /usr/lib/nfs/nfsd
    ravi 26073 23159   0 03:05:49 pts/175     0:00 grep nfsd
-sh-3.00$

pgrep commandIt is used to search process by process name and displays PID of the process.
Syntax : pgrep options pattern

The options are described below:
Option
Description
-xDisplays the PID that matches exactly
-nDisplays only the most recently created PID that matches the pattern
-U uidDisplays only the PIDs that belong to the specific user. This option uses either a user name or a UID
-lDisplays the name of the process along with the PID
-t termDisplays only those processes that are associated with a terminal in the term list

Examples:
-sh-3.00$ pgrep j
3440
1398

-sh-3.00$ pgrep -l j
 3440 java
 1398 java

-sh-3.00$ pgrep -x java
3440
1398

-sh-3.00$ pgrep -n java
1398

-sh-3.00$ pgrep -U ravi
28691
28688


Using the ptree command:
It displays a process tree based on the process ID passed as an argument. 
An argument of all digits are taken to be a PID, otherwise it is assumed to be a user login name.

Sending a Signal to a process:
Signal is a messages that is send to a process. The process responds back by performing the action that the signal requests. It is identified by a signal number and by a signal name. There is an action associated to each signal.

Signal No.Signal NameEventDefinitionDefault Response
1SIGHUPHang UpIt drops a telephone line or terminal connection. It also causes some program to re-intialize itself without terminatingExit
2SIGINTInterruptIts it generated from Key board. e.g. ctrl+CExit
9SIGKILLKillIt kills the process and a process cant ignore this signalExit
15SIGTERMTerminateIt terminates the process in orderly manner. This is the default signal that kill & pkill send.Exit

Using kill Command: It is used to send signal to one or more processes and terminates only those process that is owned by the user. A root user can kill any process. This command sends signal 15 to the process.
Syntax: kill [-signals] PIDs
Examples:

# pgrep -l java                                      
 2441 java
#kill 2441
If the process does not terminates, issue signal 9 to forcefully terminate the process as below :
#kill -9 2441


Using pkill Command: It is used to terminate the process with signal 15. We can specify the process names(to be terminated) also in this command.
Syntax: pkill [-options] pattern
The options are same as that of pgrep command.
Example:
#pkill java
We can force the process to terminate by using signal 9:
#pkill -9 -x java


No comments:

Post a Comment