Manager les processes Solaris
1 Introduction
A process is any program that is running on the system. All processes are assigned a unique process identification (PID) number, which is used by the kernel to track and manage the process. The PID numbers are used by the root and regular users to identify and control their processes.
2 prstat
The prstat command examines and displays information about active processes on the system.
This command enables you to view information by specific processes, user identification (UID) numbers, central processing unit (CPU) IDs, or processor sets. By default, the prstat command displays information about all processes sorted by CPU usage. To use the prstat command, perform the command:
To quit the prstat command, type q.
The table shows the column headings and their meanings in a prstat report. Column Headings for the prstat Report.
Default Column Heading | Description |
---|---|
PID | The PID number of the process. |
USERNAME | The login name or UID of the owner of the process. |
SIZE | The total virtual memory size of the process. |
RSS | The resident set size of the process in kilobytes, megabytes, or gigabytes. |
STATE | The state of the process: * cpu - The process is running on the CPU. * sleep - The process is waiting for an event to complete. * run - The process is in the run queue. * zombie - The process terminated, and the parent is not waiting. * stop - The process is stopped. |
PRI | The priority of the process. |
NICE | The value used in priority computation. |
TIME | The cumulative execution time for the process. |
CPU | The percentage of recent CPU time used by the process. |
PROCESS/NLWP | The name of the process/the number of lightweight processes (LWPs) in the process. |
Note: The kernel and many applications are now multithreaded. A thread is a logical sequence of program instructions written to accomplish a particular task. Each application thread is independently scheduled to run on an LWP, which functions as a virtual CPU. LWPs in turn, are attached to kernel threads, which are scheduled to run on actual CPUs.
Note: Use the priocntl(1) command to assign processes to a priority class and to manage process priorities. The nice(1) command is only supported for backward compatibility to previous Solaris OS releases. The priocntl command provides more flexibility in managing processes.
The table shows the options for the prstat command.
Option | Description |
---|---|
-a | Displays separate reports about processes and users at the same time. |
-c | Continuously prints new reports below previous reports. |
-n nproc | Restricts the number of output lines. |
-p pidlist | Reports only on processes that have a PID in the given list. |
-s key | Sorts output lines by key in descending order. The five possible keys include: cpu, time, size, rss, and pri. You can use only one key at a time. |
-S key | Sorts output lines by key in ascending order. |
-t | Reports total usage summary for each user. |
-u euidlist | Reports only processes that have an effective user ID (EUID) in the given list. |
-U uidlist | Reports only processes that have a real UID in the given list. |
3 Kill Frozen Process
You use the kill or pkill commands to terminate one or more processes.
The format for the kill command is:
kill -signal PID |
To show all of the available signals used with the kill command:
kill -l |
The format for the pkill command is:
pkill -signal Process |
Before you can terminate a process, you must know its name or PID. Use either the ps or pgrep command to locate the PID for the process.
The following examples uses the pgrep command to locate the PID for the mail processes.
# pgrep -l mail 241 sendmail 240 sendmail # pkill sendmail |
The following examples use the ps and pkill commands to locate and terminate the sendmail process.
# ps -e | grep sendmail 241 ? 0:00 sendmail 240 ? 0:02 sendmail # kill 241 |
To terminate more than one process at the same time, use the following syntax:
kill -signal PID PID PID PID pkill signal process process |
You use the kill command without a signal on the command line to send the default Signal 15 to the process. This signal usually causes the process to terminate.
The table shows some signals and names.
Signal Number | Signal Name | Event | Default Action |
---|---|---|---|
1 | SIGHUP | Hangup | Exit |
2 | SIGINT | Interrupt | Exit |
9 | SIGKILL | Kill | Exit |
15 | SIGTERM | Terminate | Exit |
- 1, SIGHUP - A hangup signal to cause a telephone line or terminal connection to be dropped. For certain daemons, such as inetd and in.named, a hangup signal will cause the daemon to reread its configuration file.
- 2, SIGINT - An interrupt signal from your keyboard--usually from a Control-C key combination.
- 9, SIGKILL - A signal to kill a process. A process cannot ignore this signal.
- 15, SIGTERM - A signal to terminate a process in an orderly manner. Some processes ignore this signal.
A complete list of signals that the kill command can send can be found by executing the command kill -l, or by referring to the man page for signal:
man -s3head signal |
Some processes can be written to ignore Signal 15. Processes that do not respond to a Signal 15 can be terminated by force by using Signal 9 with the kill or pkill commands. You use the following syntax:
kill -9 PID pkill -9 process |
Caution: Use the kill -9 or pkill -9 command as a last resort to terminate a process. Using the -9 signal on a process that controls a database application or a program that updates files can be disastrous. The process is terminated instantly with no opportunity to perform an orderly shutdown.
When a workstation is not responding to your keyboard or mouse input, the CDE might be frozen. In such cases, you may be able to remotely access your workstation by using the rlogin command or by using the telnet command from another system. Killing the Process for a Frozen Login
After you are connected remotely to your system, you can invoke the pkill command to terminate the corrupted session on your workstation.
In the following examples, the rlogin command is used to log in to sys42, from which you can issue a pkill or a kill command.
# rlogin sys-02 Password: Last login: Sun Oct 24 13:44:51 from sys-01 Sun Microsystems Inc. SunOS 5.10 s10_68 Sep. 20, 2004 # pkill -9 Xsun |
or
# ps -e | grep Xsun 442 ? 0:01 Xsun # kill -9 442 |
4 Killer les process Zombies
On rencontre de temps en temps des processus appelés zombis. Rien à voir avec un film de Georges A. Romero, il s'agit d'un phénomène beaucoup plus prosaïque. Quand un processus se termine, pratiquement toutes les ressources associées sont libérées, à l'exception de l'entrée correspondante dans la table des processus de l'OS. La raison en est simple : le processus parent doit pouvoir récupérer le code de retour de son processus fils, on ne peut donc pas tout effacer brutalement.
Typiquement, la suppression de l'entrée dans la table des processus se fait donc au moment où le parent récupère ce code retour, c'est ce qu'on appelle le reaping (the Reaper étant notre Grande Faucheuse). Si le processus parent, pour une raison où pour une autre, ne lit pas ce code, l'entrée reste présente dans la table des processus. Voyons donc à quoi ces zombis ressemblent, et comment s'en débarrasser.
En soit, c'est généralement peu gênant, puisqu'à part l'entrée dans la table des processus, il n'y a plus rien : ni mémoire consommée, ni CPU utilisé. J'y vois cependant deux inconvénients :
- la table des processus a une table limitée (30000 entrées par défaut), et chaque zombi occupe une place, donc si on en génère beaucoup, cela peut devenir problématique sur un système chargé
- le zombi est vraiment, vraiment laid (et en plus il ne sent pas bon)
Fort heureusement, il est possible de se substituer au parent négligent et de permettre enfin à ces zombis de trouver le repos éternel. Voyons déjà comment apparaît un zombi sur le système :
ps |
$ ps -edf |
Ou encore :
ps |
$ ps -ecl |
Pour les supprimer, on va utiliser la commande preap :
preap |
$ preap 7450 7450: exited with status 0 $ preap 7542 7542: exited with status 0 $ preap 7544 7544: exited with status 0 $ preap 7546 7546: exited with status 0 $ ps -edf | grep defunct |
Et voilà, bigrement plus efficace que le héros de Brain Dead! A noter, si vous souhaitez créer manuellement un zombi pour vos tests, vous pouvez utiliser la commande suivante, fournie par l'excellent c0t0d0s0.org :
nohup |
nohup perl -e "if (fork()>0) {while (1) {sleep 100*100;};};" |