Linux commands to display the system processes information
ps command
kodingwindow@kw:~$ ps PID TTY TIME CMD 3368 pts/0 00:00:00 bash 3372 pts/0 00:00:00 ps kodingwindow@kw:~$ ps -a PID TTY TIME CMD 2377 tty2 00:00:08 Xorg 2417 tty2 00:00:00 gnome-session-b 3373 pts/0 00:00:00 ps kodingwindow@kw:~$ ps -aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.5 0.1 167952 11684 ? Ss 18:24 0:01 /sbin/init sp root 2 0.0 0.0 0 0 ? S 18:24 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? I< 18:24 0:00 [rcu_gp] root 4 0.0 0.0 0 0 ? I< 18:24 0:00 [rcu_par_gp] root 5 0.3 0.0 0 0 ? I 18:24 0:01 [kworker/0:0- root 6 0.0 0.0 0 0 ? I< 18:24 0:00 [kworker/0:0H . . . root 3380 0.0 0.0 24724 5840 ? S 18:30 0:00 /lib/systemd/ root 3579 0.0 0.0 9492 3348 ? S 18:30 0:00 /bin/bash /et root 3585 0.0 0.0 8272 776 ? S 18:30 0:00 flock --nonbl root 3586 4.5 0.0 8168 2328 ? DN 18:30 0:00 /usr/bin/upda kodingw+ 3587 0.0 0.0 11888 3724 pts/0 R+ 18:30 0:00 ps -aux kodingwindow@kw:~$
Extract specific columns
kodingwindow@kw:~$ ps -e PID TTY TIME CMD 1 ? 00:00:02 systemd 2 ? 00:00:00 kthreadd 3 ? 00:00:00 rcu_gp 4 ? 00:00:00 rcu_par_gp 5 ? 00:00:01 kworker/0:0-events 6 ? 00:00:00 kworker/0:0H-kblockd 8 ? 00:00:01 kworker/u8:0-events_unbound 9 ? 00:00:00 mm_percpu_wq 10 ? 00:00:00 ksoftirqd/0 kodingwindow@kw:~$ ps -eo pid,ppid,ni PID PPID NI 1 0 0 2 0 0 3 2 -20 4 2 -20 5 2 0 6 2 -20 8 2 0 9 2 -20
Sort processes based on column attributes
kodingwindow@kw:~$ ps aux --sort user USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND avahi 949 0.0 0.0 8808 3676 ? Ss 18:25 0:00 avahi-daemon: avahi 1003 0.0 0.0 8544 356 ? S 18:25 0:00 avahi-daemon: kodingw+ 2286 0.0 0.1 19472 10760 ? Ss 18:26 0:00 /lib/systemd/ kodingw+ 2287 0.0 0.0 169324 3816 ? S 18:26 0:00 (sd-pam) kodingw+ 2300 0.0 0.2 2268840 19676 ? S<sl 18:27 0:00 /usr/bin/puls kodingw+ 2302 0.0 0.3 511384 24320 ? SNsl 18:27 0:00 /usr/libexec/ kodingw+ 2305 0.0 0.0 8452 5624 ? Ss 18:27 0:00 /usr/bin/dbus kodingw+ 2310 0.0 0.0 240184 7716 ? Sl 18:27 0:00 /usr/bin/gnom kodingw+ 2325 0.0 0.0 239696 7820 ? Ssl 18:27 0:00 /usr/libexec/
Extract specific process
kodingwindow@kw:~$ ps -aux | grep mysql mysql 1172 1.1 4.4 2120856 352952 ? Ssl 18:25 0:04 /usr/sbin/mysqld kodingw+ 3607 0.0 0.0 8900 724 pts/0 S+ 18:32 0:00 grep mysql kodingwindow@kw:~$ pgrep mysql 1172 kodingwindow@kw:~$ pgrep -l mysql 1172 mysqld kodingwindow@kw:~$ ps -lp 1172 F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 4 S 122 1172 1 1 80 0 - 530214 - ? 00:00:10 mysqld
Assign and change the process priority
kodingwindow@kw:~$ su Password: root@kw:/home/kodingwindow# ps -l F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 4 S 0 4426 4424 0 80 0 - 2875 do_wai pts/0 00:00:00 su 4 S 0 4427 4426 0 80 0 - 2546 do_wai pts/0 00:00:00 bash 4 R 0 4440 4427 0 80 0 - 2849 - pts/0 00:00:00 ps root@kw:/home/kodingwindow# nice 0 root@kw:/home/kodingwindow# nice -n 5 bash root@kw:/home/kodingwindow# ps -l F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 4 S 0 4426 4424 0 80 0 - 2875 do_wai pts/0 00:00:00 su 4 S 0 4427 4426 0 80 0 - 2546 do_wai pts/0 00:00:00 bash 0 S 0 4442 4427 0 85 5 - 2545 do_wai pts/0 00:00:00 bash 4 R 0 4453 4442 0 85 5 - 2849 - pts/0 00:00:00 ps root@kw:/home/kodingwindow# renice -0 4442 4442 (process ID) old priority 5, new priority 0 root@kw:/home/kodingwindow# ps -l F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 4 S 0 4426 4424 0 80 0 - 2875 do_wai pts/0 00:00:00 su 4 S 0 4427 4426 0 80 0 - 2546 do_wai pts/0 00:00:00 bash 0 S 0 4442 4427 0 80 0 - 2545 do_wai pts/0 00:00:00 bash 4 R 0 4455 4442 0 80 0 - 2849 - pts/0 00:00:00 ps root@kw:/home/kodingwindow# renice -21 4442 4442 (process ID) old priority 0, new priority -20 root@kw:/home/kodingwindow# ps -l F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 4 S 0 4426 4424 0 80 0 - 2875 do_wai pts/0 00:00:00 su 4 S 0 4427 4426 0 80 0 - 2546 do_wai pts/0 00:00:00 bash 0 S 0 4442 4427 0 60 -20 - 2545 do_wai pts/0 00:00:00 bash 4 R 0 4476 4442 0 60 -20 - 2849 - pts/0 00:00:00 ps root@kw:/home/kodingwindow#
pstree command
kodingwindow@kw:~$ pstree systemd─┬─ModemManager───2*[{ModemManager}] ├─NetworkManager───2*[{NetworkManager}] ├─accounts-daemon───2*[{accounts-daemon}] ├─acpid ├─avahi-daemon───avahi-daemon ├─bluetoothd ├─colord───2*[{colord}] ├─cron ├─cups-browsed───2*[{cups-browsed}] ├─cupsd ├─dbus-daemon ├─gdm3─┬─gdm-session-wor─┬─gdm-x-session─┬─Xorg───13*[{Xorg}] │ │ │ ├─gnome-session-b─┬─ssh-agent │ │ │ │ └─2*[{gnome-+ │ │ │ └─2*[{gdm-x-session}] │ │ └─2*[{gdm-session-wor}] │ └─2*[{gdm3}] ├─geoclue───2*[{geoclue}] ├─gnome-keyring-d───3*[{gnome-keyring-d}] ├─ibus-daemon─┬─ibus-dconf───3*[{ibus-dconf}] │ ├─ibus-engine-sim───2*[{ibus-engine-sim}] │ ├─ibus-extension-───3*[{ibus-extension-}] │ ├─ibus-ui-gtk3───3*[{ibus-ui-gtk3}] ...
top command
kodingwindow@kw:~$ top top - 18:38:14 up 13 min, 1 user, load average: 0.63, 0.87, 0.87 Tasks: 224 total, 1 running, 223 sleeping, 0 stopped, 0 zombie %Cpu(s): 4.7 us, 2.0 sy, 0.0 ni, 93.1 id, 0.0 wa, 0.0 hi, 0.2 si, 0.0 st MiB Mem : 7744.8 total, 4550.7 free, 1583.5 used, 1610.6 buff/cache MiB Swap: 3815.0 total, 3815.0 free, 0.0 used. 5675.2 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 3099 kodingw+ 20 0 2987604 367320 170248 S 8.0 4.6 0:40.19 MainThr+ 2377 kodingw+ 20 0 1143856 87276 54980 S 7.0 1.1 0:32.62 Xorg 2629 kodingw+ 20 0 4488208 257140 101068 S 6.0 3.2 0:40.69 gnome-s+ 3357 kodingw+ 20 0 962192 51452 39424 S 3.0 0.6 0:08.14 gnome-t+ 3296 kodingw+ 20 0 2684072 250256 153392 S 2.0 3.2 0:18.56 Web Con+ 433 root -51 0 0 0 0 S 1.0 0.0 0:02.03 irq/87-+ 1 root 20 0 167952 11684 8228 S 0.7 0.1 0:02.50 systemd 1172 mysql 20 0 2120856 352952 33540 S 0.7 4.5 0:08.17 mysqld 2506 kodingw+ 20 0 311420 7728 6056 S 0.7 0.1 0:03.57 ibus-da+ 3737 kodingw+ 20 0 12168 4240 3444 R 0.7 0.1 0:00.14 top 8 root 20 0 0 0 0 I 0.3 0.0 0:01.17 kworker+ 2515 kodingw+ 20 0 674584 58852 39052 S 0.3 0.7 0:01.86 ibus-ex+ 2592 kodingw+ 20 0 162684 7048 6412 S 0.3 0.1 0:00.99 ibus-en+ 3203 kodingw+ 20 0 2765492 248912 139908 S 0.3 3.1 1:08.42 Web Con+ 3610 root 20 0 0 0 0 I 0.3 0.0 0:00.56 kworker+ 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd 3 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_gp
What Next?
Bash Shell Scripting
Advertisement