You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/books/admin_guide/08-process.md
+95-4Lines changed: 95 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -378,19 +378,110 @@ The `pkill` command will send the specified signal (by default _SIGTERM_) to eac
378
378
379
379
```
380
380
pgrep process
381
-
pkill [-signal] process
381
+
pkill [option] [-signal] process
382
382
```
383
383
384
384
Examples:
385
385
386
386
* Get the process number from `sshd`:
387
387
388
+
```
389
+
$ pgrep -u root sshd
390
+
```
391
+
392
+
* Kill all `tomcat` processes:
393
+
394
+
```
395
+
$ pkill tomcat
396
+
```
397
+
398
+
!!! note
399
+
400
+
Before you decide to kill a process, it's best to know exactly what the process is for, otherwise it can lead to system crashes or other unpredictable problems.
401
+
402
+
In addition to sending signals to the relevant processes, the `pkill` command can also end the user's connection session according to the terminal number, such as:
403
+
388
404
```
389
-
$ pgrep -u root sshd
405
+
$ pkill -t pts/1
390
406
```
391
407
392
-
* Kill all `tomcat` processes:
408
+
### `killall` command
409
+
410
+
The function of this command is roughly the same as that of the `pkill` command. The usage is - `killall [option] [ -s SIGNAL | -SIGNAL ] NAME`. The default signal is _SIGTERM_.
411
+
412
+
| Options | Description |
413
+
| :--- | :--- |
414
+
|`-l`| list all known signal names |
415
+
|`-i`| ask for confirmation before killing |
416
+
|`-I`| case insensitive process name match |
417
+
418
+
Example:
419
+
420
+
```
421
+
$ killall tomcat
422
+
```
423
+
424
+
### `pstree` command
425
+
426
+
This command displays the progress in a tree style and its usage is - `pstree [option]`.
427
+
428
+
| Option | Description |
429
+
| :--- | :--- |
430
+
|`-p`| Displays the PID of the process |
431
+
|`-n`| sort output by PID |
432
+
|`-h`| highlight current process and its ancestors |
**orphan process**: When a parent process dies, its children are said to be orphans. These special state processes are adopted by the init process and status collection is completed until they are destroyed. Conceptually speaking, the orphanage process does not pose any harm.
463
+
464
+
**zombie process**: After a child process completes its work and is terminated, its parent process needs to call the signal processing function wait() or waitpid() to obtain the termination status of the child process. If the parent process does not do so, although the child process has already exited, it still retains some exit status information in the system process table, because the parent process cannot obtain the status information of the child process, these processes will continue to occupy resources in the process table. We refer to processes in this state as zombies.
465
+
466
+
Hazard:
467
+
468
+
* Occupying system resources and causing a decrease in machine performance.
469
+
* Unable to generate new child processes.
470
+
471
+
How to check if there are any zombie processes in the current system?
393
472
394
473
```
395
-
$ pkill tomcat
474
+
$ ps -lef | awk '{print $2}' | grep Z
396
475
```
476
+
477
+
These characters may appear in this column:
478
+
479
+
***D** - uninterruptible sleep (usually IO)
480
+
***I** - Idle kernel thread
481
+
***R** - running or runnable (on run queue)
482
+
***S** - interruptible sleep (waiting for an event to complete)
483
+
***T** - stopped by job control signal
484
+
***t** - stopped by debugger during the tracing
485
+
***W** - paging (not valid since the 2.6.xx kernel)
486
+
***X** - dead (should never be seen)
487
+
***Z** - defunct ("zombie") process, terminated but not reaped by its parent
0 commit comments