Chapter 8
MONITORING AND MANAGING LINUX PROCESSES
PS
RHEL9-da ən birinci başlayan proses systemd prosesidir. Bütün digər proseslər systemd-nin child prosesləridir. Hər prosesin İD-si, hər child prosesin isə PPİD (parent's process ID)-si olur.
Parent prosesdən child proses yaranarkən, child proses parentin bütün özəlliklərini (environment variables, səlahiyyətlər, current file descriptorları, portları və s.) məlumtları inherit edir. Child proses yarandıqda parent proses wait əmriylə gözləmə rejiminə keçir. Child proses öz işini bitirdikdən sonra özünə aid olan bir çox resusları silsə də, process table-da zombie proses olaraq onun entry-si qalmaqda davam edir.
Child process exit etdikdən sonra parent process process table-da child-in zombie entrysini silir və öz fəaliyyətinə davam edir.
Linuxda proseslərə baxmaq aşağıdakı yollarla mümkündür:
sudo vasitəsilə ps işlətdikdə TTY sual işarəsi görsənməsinin səbəbi, bəzi proseslər system daemon tərəfindən başladıldığı üçün onların heç bir TTY-ə aid olmamasıdır.
top komandası vasitəsilə S sütununa baxdıqda proses state-ləri görmək mümkündür.
ps -aux komandası vasitəsilə STAT sütununa baxdıqda stateləri görmək mümkündür. PS komandası outputu 3 fərqli formatda verə bilir (GNU, POSİX və BSD). Bu səbəbdən ps arqumentində -
işlətmək outputu dəyişir. Məsələn, ps -ef
və ps ef
eyni outputu verməyəcək.
Running
R
TASK_RUNNING:
Proses CPU üzərində fəaliyyətdədir, ya da fəaliyyətə düşməyi gözləyir.
Process can be executing user routines or kernel routines (system calls), or be queued and ready when in the Running (or Runnable) state.
Sleeping
S
TASK_INTERRUPTIBLE:
Proses üçündən birindən cavab almaqçün gözləyir:
Hardware request
System resource access
Signal
Şərait təmin olunduqda, proses Running state-ə geri qayıdacaq.
D
TASK_UNINTERRUPTIBLE:
D flagının S-dən fərqi ondadır ki, heç bir siqnala cavab vermir.
Yalnız prosesin dayanması cihazı gözlənilməz vəziyyətə gətirib çıxarma ehtimalı varsa istifadə olunur.
K
TASK_KILLABLE:
D ilə eynidir, sadəcə exception kimi fatal signallara KİLL siqnalına (tamamilə prosesdi sonlandırma) cavab verir.
Utilities frequently display Killable processes as D state.
I
TASK_REPORT_IDLE:
Kernel threadları üçün istifadə olunur.
A subset of state D. The kernel does not count these processes when calculating load average. Used for kernel threads. Flags TASK_UNINTERRUPTABLE and TASK_NOLOAD are set. Similar to TASK_KILLABLE, also a subset of state D. It accepts fatal signals.
Stopped
T
TASK_STOPPED:
İstifadəçi vəya digər proses tərəfindən proses dayandırılmışdır (stopped/suspended).
Proses resume edilərək Running state-ə qaytarıla bilər.
T
TASK_TRACED:
Proses hal-hazırda debug olunur və müvəqqəti olaraq dayandırılmışdır (stopped).
Zombie
Z
EXIT_ZOMBIE:
Child proses parentə exit olması haqqında signal verir. PID istisna olmaqla digər bütün resurslar silinir.
X
EXIT_DEAD:
Parent, child prosesin geridə qalmış proses strukturlarını sildikdən sonra bu state-ə gəlir. Bu state heç vaxt process-listing alətlərində görsənmir.
Jobs
Eyni terminal session-dan bir neçə prosesi idarə etmək üçün yaradılmış funksionallıqdır.
kill
1
HUP
Hangup
Used to report termination of the controlling process of a terminal. Also used to request process reinitialization (configuration reload) without termination.
2
INT
Keyboard interrupt
Causes program termination. Can be blocked or handled. Sent by pressing INTR key combination (Ctrl+C).
3
QUIT
Keyboard quit
Similar to SIGINT, but also produces a process dump at termination. Sent by pressing QUIT key combination (Ctrl+\).
9
KILL
Kill, unblockable
Causes abrupt program termination. Cannot be blocked, ignored, or handled; always fatal.
15
default
TERM
Terminate
Causes program termination. Unlike SIGKILL, can be blocked, ignored, or handled. The “polite” way to ask a program to terminate; allows self-cleanup.
18
CONT
Continue
Sent to a process to resume, if stopped. Cannot be blocked. Even if handled, always resumes the process.
19
STOP
Stop, unblockable
Suspends the process. Cannot be blocked or handled.
20
TSTP
Keyboard stop
Unlike SIGSTOP, can be blocked, ignored, or handled. Sent by pressing SUSP key combination (Ctrl+Z).
Hər bir signalın default actionu var:
1) Term - prosesi terminate (exit) edir
2) Core - prosesin memory imageini dump edir, sonra exit edir
3) Stop - prosesi (stop) edir, və davam etmək üçün (resume) gözləyir.
Signal nömrələri fərqli linux distrolarında müxtəlifdir, signal adları isə standartlaşdırılmışdır, bu səbəbdən komandaların icrasında signal nömrələrini yox adları yazmaq daha məqsədəuyğundur.
Məsələn, arxa fonda işləyən jobu aşağıdakı qaydada STOP etmək mümkündür:
Killall pkill-ə nisbətən daha aqresiv komandadır. Hər iki komanda prosesin PİD-sini yox adını bildikdə, onu sonlandırmaq üçün istifadəyə yarayır.
Remotely logging out users
İstifadəçilərin hansı tty-dən istifadə etdiyini aydınlaşdırmaq üçün w
əmrini icra edirik.
tty/n - terminal device
pts/n - pseudo-terminal associated with a graphical terminal window or remote login session
Burada JCPU
istifadəçinin background joblarının CPU istifadəsini, PCPU
isə foreground jobların CPU istifadəsini göstərir.
Birinci SİGTERM, sonra SİGİNT, sonra SİGKİLL əmrləri göndərilməlidir. Çünki proseslər birinci SİGKİLL ilə kill edilərsə, onlar adətən self-cleanup tədbirləri görmürlər.
MONITORING PROCESS ACTIVITY
PID:
The Process ID number of the process.
USER:
The username of the user who owns the process.
PR:
Priority of the process. This is the priority with which the kernel schedules the process.
NI:
The nice value of the process, which is a user-space concept used to influence the scheduling priority. Nice values range from -20 (highest priority) to 19 (lowest priority).
VIRT:
Virtual Memory Size of the process, which includes all code, data and shared libraries plus pages that have been swapped out and pages that have been mapped but not used.
RES:
Resident Set Size: the non-swapped physical memory a task has used.
SHR:
Shared memory size: The amount of shared memory used by a task. It reflects memory shared with other processes.
S:
Process Status:
D
is for uninterruptible sleep (usually IO).R
is for running.S
is for sleeping.T
is for traced or stopped.Z
is for zombie.
%CPU:
The percentage of the CPU time that the task has received recently.
%MEM:
The percentage of the total memory used by the process.
TIME+:
The total CPU time the task has used since it started.
COMMAND:
The command that initiated the process.
KEY
PURPOSE
?orH
Help for interactive keystrokes.
L,T,M
Toggles for load, threads, and memory header lines.
1
Toggle showing individual CPUs or a summary for all CPUs in header.
S (1)
Change the refresh (screen) rate, in decimal seconds (e.g., 0.5, 1, 5).
B
Toggle reverse highlighting for Running processes; default is bold only.
B
Enables use of bold in display, in the header, and for Running processes.
Shift+H
Toggle threads; show process summary or individual threads.
U, Shift+U
Filter for any user name (effective, real).
Shift+M
Sorts process listing by memory usage, in descending order.
Shift+P
Sorts process listing by processor utilization, in descending order.
K (1)
Kill a process. When prompted, enter PID, then signal.
R (1)
Renice a process. When prompted, enter PID, then nice_value.
Shift+W
Write (save) the current display configuration for use at the next top restart.
Q
Quit.
Last updated
Was this helpful?