系统进程
本博文的主要內容有
.進程簡介
.查看linux系統進程的分布結構
.查看linux系統當前,有哪些進程在運行
.對linux系統進行動態監控
.進程的創建和終止
.什么是后臺進程
.什么時候使用后臺進程
1、進程簡介
2、系統進程信息
3、進程創建
4、進程終止
進程簡介
系統啟動的第一個進程是init進程,系統中的其他進程都由此進程產生并受它控制。所謂進程,被認為是一個具有獨立功能的程序,在一個數據集合上的一次動態執行過程。但,需要注意,一個進程只能對應一個程序。
進程通常由3部分組成:程序、數據集合和進程控制塊(PCB)。
在linux系統中,每一個進程都有一個唯一的標識符,即進程ID,簡稱PID。此PID是在進程啟動進程啟動時系統為其分配的,除了init進程外,其他進程都是系統通過調研fork()和clone()函數創建的進程。
系統進程信息
pstree 查看linux系統中進程的分布結構
出現,這種現象,是編碼的問題而已。鼠標,放到會話窗口,右鍵,點擊Session Options,
[root@weekend110 ~]# pstree
init─┬─NetworkManager
├─abrtd
├─acpid
├─atd
├─auditd───{auditd}
├─automount───4*[{automount}]
├─bonobo-activati───{bonobo-activat}
├─certmonger
├─console-kit-dae───63*[{console-kit-da}]
├─crond
├─cupsd
├─2*[dbus-daemon───{dbus-daemon}]
├─dbus-launch
├─devkit-power-da
├─gconfd-2
├─gdm-binary─┬─gdm-simple-slav─┬─Xorg
│ │ ├─gdm-session-wor
│ │ ├─gnome-session─┬─at-spi-registry
│ │ │ ├─gdm-simple-gree
│ │ │ ├─gnome-power-man
│ │ │ ├─metacity
│ │ │ ├─plymouth-log-vi
│ │ │ ├─polkit-gnome-au
│ │ │ └─{gnome-session}
│ │ └─{gdm-simple-sla}
│ └─{gdm-binary}
├─gnome-settings-───{gnome-settings}
├─gvfsd
├─hald─┬─hald-runner─┬─hald-addon-acpi
│ │ └─hald-addon-inpu
│ └─{hald}
├─master─┬─pickup
│ └─qmgr
├─5*[mingetty]
├─modem-manager
├─polkitd
├─pulseaudio───2*[{pulseaudio}]
├─rpc.statd
├─rpcbind
├─rsyslogd───3*[{rsyslogd}]
├─rtkit-daemon───2*[{rtkit-daemon}]
├─sshd───sshd───bash───pstree
├─udevd───2*[udevd]
└─wpa_supplicant
[root@weekend110 ~]#
由此可見,進程是逐級創建的,因此其顯得像一顆倒立的樹,樹最頂層的進程是init進程,即根進程。
在命令后加上“&” 使進程后臺運行
ps 查看linux系統中當前哪些進程在運行
每行字段為一行。
以1848 pts/0 00:00:00 bash為例
1848是PID,即進程ID。
pts/0為該進程所使用的終端號
00:00:00是該進程運行時占用CPU的時間
bash是為啟動該進程的命令,其中bash是登錄系統后執行的第一條命令,而ps則是在輸入ps時所執行的命令。
[root@weekend110 ~]# ps
PID TTY TIME CMD
1848 pts/0 00:00:00 bash
1893 pts/0 00:00:00 ps
[root@weekend110 ~]#
以root 1 0 0 09:10 ? 00:00:03 /sbin/init為例
root 是UID,即運行該進程的用戶
1是PID,即進程ID
0是PPID,即父進程ID
0是C,即執行該進程時CPU調度的情況
09:10是STIME,該進程的啟動時間
?是TTY,所使用的虛擬終端號
00:00:03是TIME,是進程所使用的CPU時間
/sbin/init是CMD,是啟動該進程的命令
[root@weekend110 ~]# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 09:10 ? 00:00:03 /sbin/init
root 2 0 0 09:10 ? 00:00:00 [kthreadd]
root 3 2 0 09:10 ? 00:00:00 [migration/0]
root 4 2 0 09:10 ? 00:00:00 [ksoftirqd/0]
root 5 2 0 09:10 ? 00:00:00 [migration/0]
root 6 2 0 09:10 ? 00:00:00 [watchdog/0]
root 7 2 0 09:10 ? 00:00:01 [events/0]
root 8 2 0 09:10 ? 00:00:00 [cgroup]
root 9 2 0 09:10 ? 00:00:00 [khelper]
root 10 2 0 09:10 ? 00:00:00 [netns]
root 11 2 0 09:10 ? 00:00:00 [async/mgr]
root 12 2 0 09:10 ? 00:00:00 [pm]
root 13 2 0 09:10 ? 00:00:00 [sync_supers]
root 14 2 0 09:10 ? 00:00:00 [bdi-default]
root 15 2 0 09:10 ? 00:00:00 [kintegrityd/0]
root 16 2 0 09:10 ? 00:00:00 [kblockd/0]
root 17 2 0 09:10 ? 00:00:00 [kacpid]
root 18 2 0 09:10 ? 00:00:00 [kacpi_notify]
root 19 2 0 09:10 ? 00:00:00 [kacpi_hotplug]
root 20 2 0 09:10 ? 00:00:00 [ata_aux]
root 21 2 0 09:10 ? 00:00:00 [ata_sff/0]
root 22 2 0 09:10 ? 00:00:00 [ksuspend_usbd]
root 23 2 0 09:10 ? 00:00:00 [khubd]
root 24 2 0 09:10 ? 00:00:00 [kseriod]
root 25 2 0 09:10 ? 00:00:00 [md/0]
root 26 2 0 09:10 ? 00:00:00 [md_misc/0]
root 27 2 0 09:10 ? 00:00:00 [linkwatch]
root 28 2 0 09:10 ? 00:00:00 [khungtaskd]
root 29 2 0 09:10 ? 00:00:00 [kswapd0]
root 30 2 0 09:10 ? 00:00:00 [ksmd]
root 31 2 0 09:10 ? 00:00:00 [khugepaged]
root 32 2 0 09:10 ? 00:00:00 [aio/0]
root 33 2 0 09:10 ? 00:00:00 [crypto/0]
root 38 2 0 09:10 ? 00:00:00 [kthrotld/0]
root 39 2 0 09:10 ? 00:00:00 [pciehpd]
root 41 2 0 09:10 ? 00:00:00 [kpsmoused]
root 42 2 0 09:10 ? 00:00:00 [usbhid_resumer]
root 72 2 0 09:10 ? 00:00:00 [kstriped]
root 147 2 0 09:10 ? 00:00:00 [scsi_eh_0]
root 148 2 0 09:10 ? 00:00:00 [scsi_eh_1]
root 155 2 0 09:10 ? 00:00:00 [mpt_poll_0]
root 156 2 0 09:10 ? 00:00:00 [mpt/0]
root 157 2 0 09:10 ? 00:00:00 [scsi_eh_2]
root 279 2 0 09:10 ? 00:00:00 [flush-8:0]
root 285 2 0 09:10 ? 00:00:00 [jbd2/sda5-8]
root 286 2 0 09:10 ? 00:00:00 [ext4-dio-unwrit]
root 376 1 0 09:10 ? 00:00:01 /sbin/udevd -d
root 716 2 0 09:10 ? 00:00:00 [vmmemctl]
root 915 2 0 09:10 ? 00:00:00 [jbd2/sda1-8]
root 916 2 0 09:10 ? 00:00:00 [ext4-dio-unwrit]
root 917 2 0 09:10 ? 00:00:00 [jbd2/sda2-8]
root 918 2 0 09:10 ? 00:00:00 [ext4-dio-unwrit]
root 1010 2 0 09:10 ? 00:00:00 [kauditd]
root 1212 1 0 09:10 ? 00:00:00 auditd
root 1237 1 0 09:10 ? 00:00:00 /sbin/rsyslogd -i /var/run/syslogd.pid -c 5
rpc 1280 1 0 09:10 ? 00:00:00 rpcbind
dbus 1295 1 0 09:10 ? 00:00:00 dbus-daemon --system
root 1306 1 0 09:10 ? 00:00:00 NetworkManager --pid-file=/var/run/NetworkManager/NetworkManager.pid
root 1312 1 0 09:10 ? 00:00:00 /usr/sbin/modem-manager
rpcuser 1325 1 0 09:10 ? 00:00:00 rpc.statd
root 1380 1 0 09:10 ? 00:00:00 /usr/sbin/wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -B -u -f /var/l
root 1381 1 0 09:10 ? 00:00:00 cupsd -C /etc/cups/cupsd.conf
root 1398 1 0 09:11 ? 00:00:00 /usr/sbin/acpid
68 1407 1 0 09:11 ? 00:00:00 hald
root 1408 1407 0 09:11 ? 00:00:00 hald-runner
root 1450 1408 0 09:11 ? 00:00:00 hald-addon-input: Listening on /dev/input/event2 /dev/input/event0
68 1461 1408 0 09:11 ? 00:00:00 hald-addon-acpi: listening on acpid socket /var/run/acpid.socket
root 1481 1 0 09:11 ? 00:00:00 automount --pid-file /var/run/autofs.pid
root 1506 1 0 09:11 ? 00:00:00 /usr/sbin/sshd
root 1586 1 0 09:11 ? 00:00:00 /usr/libexec/postfix/master
postfix 1594 1586 0 09:11 ? 00:00:00 pickup -l -t fifo -u
postfix 1595 1586 0 09:11 ? 00:00:00 qmgr -l -t fifo -u
root 1610 1 0 09:11 ? 00:00:00 /usr/sbin/abrtd
root 1618 1 0 09:11 ? 00:00:03 crond
root 1629 1 0 09:11 ? 00:00:00 /usr/sbin/atd
root 1641 1 0 09:11 ? 00:00:00 /usr/sbin/certmonger -S -p /var/run/certmonger.pid
root 1649 1 0 09:11 ? 00:00:00 /usr/sbin/gdm-binary -nodaemon
root 1654 1 0 09:11 tty2 00:00:00 /sbin/mingetty /dev/tty2
root 1656 1 0 09:11 tty3 00:00:00 /sbin/mingetty /dev/tty3
root 1658 1 0 09:11 tty4 00:00:00 /sbin/mingetty /dev/tty4
root 1660 1 0 09:11 tty5 00:00:00 /sbin/mingetty /dev/tty5
root 1668 1 0 09:11 tty6 00:00:00 /sbin/mingetty /dev/tty6
root 1669 376 0 09:11 ? 00:00:00 /sbin/udevd -d
root 1670 376 0 09:11 ? 00:00:00 /sbin/udevd -d
root 1685 1649 0 09:11 ? 00:00:00 /usr/libexec/gdm-simple-slave --display-id /org/gnome/DisplayManager/Display1 --for
root 1688 1685 0 09:11 tty1 00:00:03 /usr/bin/Xorg :0 -nr -verbose -audit 4 -auth /var/run/gdm/auth-for-gdm-OMcqii/datab
root 1704 1 0 09:11 ? 00:00:00 /usr/sbin/console-kit-daemon --no-daemon
gdm 1774 1 0 09:11 ? 00:00:00 /usr/bin/dbus-launch --exit-with-session
gdm 1775 1 0 09:11 ? 00:00:00 /bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
gdm 1777 1685 0 09:11 ? 00:00:00 /usr/bin/gnome-session --autostart=/usr/share/gdm/autostart/LoginWindow/
root 1780 1 0 09:11 ? 00:00:00 /usr/libexec/devkit-power-daemon
gdm 1784 1 0 09:11 ? 00:00:00 /usr/libexec/gconfd-2
root 1797 1506 0 09:11 ? 00:00:00 sshd: root@pts/0
gdm 1801 1777 0 09:11 ? 00:00:00 /usr/libexec/at-spi-registryd
gdm 1805 1 0 09:11 ? 00:00:01 /usr/libexec/gnome-settings-daemon --gconf-prefix=/apps/gdm/simple-greeter/settings
gdm 1807 1 0 09:11 ? 00:00:00 /usr/libexec/bonobo-activation-server --ac-activate --ior-output-fd=12
gdm 1816 1 0 09:11 ? 00:00:00 /usr/libexec/gvfsd
gdm 1817 1777 0 09:11 ? 00:00:00 metacity
gdm 1818 1777 0 09:11 ? 00:00:00 /usr/libexec/polkit-gnome-authentication-agent-1
gdm 1819 1777 0 09:11 ? 00:00:00 plymouth-log-viewer --icon
gdm 1820 1777 0 09:11 ? 00:00:00 gnome-power-manager
gdm 1821 1777 0 09:11 ? 00:00:00 /usr/libexec/gdm-simple-greeter
root 1824 1 0 09:11 ? 00:00:00 /usr/libexec/polkit-1/polkitd
gdm 1833 1 0 09:11 ? 00:00:04 /usr/bin/pulseaudio --start --log-target=syslog
rtkit 1835 1 0 09:11 ? 00:00:00 /usr/libexec/rtkit-daemon
root 1842 1685 0 09:11 ? 00:00:00 pam: gdm-password
root 1848 1797 0 09:12 pts/0 00:00:00 -bash
root 1957 1848 0 09:26 pts/0 00:00:00 ps -ef
[root@weekend110 ~]#
ps -ef | more 更直觀,利用管道傳送到more中顯示,使用空格鍵查看下一頁,按q鍵或ctrl +c 退出
[root@weekend110 ~]# ps -ef | more
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 09:10 ? 00:00:03 /sbin/init
root 2 0 0 09:10 ? 00:00:00 [kthreadd]
root 3 2 0 09:10 ? 00:00:00 [migration/0]
root 4 2 0 09:10 ? 00:00:00 [ksoftirqd/0]
root 5 2 0 09:10 ? 00:00:00 [migration/0]
root 6 2 0 09:10 ? 00:00:00 [watchdog/0]
root 7 2 0 09:10 ? 00:00:01 [events/0]
root 8 2 0 09:10 ? 00:00:00 [cgroup]
root 9 2 0 09:10 ? 00:00:00 [khelper]
root 10 2 0 09:10 ? 00:00:00 [netns]
root 11 2 0 09:10 ? 00:00:00 [async/mgr]
root 12 2 0 09:10 ? 00:00:00 [pm]
root 13 2 0 09:10 ? 00:00:00 [sync_supers]
root 14 2 0 09:10 ? 00:00:00 [bdi-default]
root 15 2 0 09:10 ? 00:00:00 [kintegrityd/0]
root 16 2 0 09:10 ? 00:00:00 [kblockd/0]
root 17 2 0 09:10 ? 00:00:00 [kacpid]
root 18 2 0 09:10 ? 00:00:00 [kacpi_notify]
root 19 2 0 09:10 ? 00:00:00 [kacpi_hotplug]
root 20 2 0 09:10 ? 00:00:00 [ata_aux]
root 21 2 0 09:10 ? 00:00:00 [ata_sff/0]
root 22 2 0 09:10 ? 00:00:00 [ksuspend_usbd]
root 23 2 0 09:10 ? 00:00:00 [khubd]
root 24 2 0 09:10 ? 00:00:00 [kseriod]
root 25 2 0 09:10 ? 00:00:00 [md/0]
root 26 2 0 09:10 ? 00:00:00 [md_misc/0]
root 27 2 0 09:10 ? 00:00:00 [linkwatch]
root 28 2 0 09:10 ? 00:00:00 [khungtaskd]
root 29 2 0 09:10 ? 00:00:00 [kswapd0]
root 30 2 0 09:10 ? 00:00:00 [ksmd]
root 31 2 0 09:10 ? 00:00:00 [khugepaged]
root 32 2 0 09:10 ? 00:00:00 [aio/0]
root 33 2 0 09:10 ? 00:00:00 [crypto/0]
root 38 2 0 09:10 ? 00:00:00 [kthrotld/0]
root 39 2 0 09:10 ? 00:00:00 [pciehpd]
--More--
ps nux 查看linux系統中所有進程的資源使用情況
以root 1 0.2 0.0 19356 1540 ? Ss 09:10 0:03 /sbin/init為例
root是USER,是運行該進程的用戶
0.2是%CPU,是運行該進程時CPU的使用率
0.0是%MEM,是運行進程時內存的使用率
19356是VSZ,是進程占用虛擬內存的大小
Ss是STAT,是進程的狀態,S表示睡眠,R表示在運行
09:10是START,是進程的啟動時間
/sbin/init是COMMAND,是啟動進程的命令
[root@weekend110 ~]# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.2 0.0 19356 1540 ? Ss 09:10 0:03 /sbin/init
root 2 0.0 0.0 0 0 ? S 09:10 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S 09:10 0:00 [migration/0]
root 4 0.0 0.0 0 0 ? S 09:10 0:00 [ksoftirqd/0]
root 5 0.0 0.0 0 0 ? S 09:10 0:00 [migration/0]
root 6 0.0 0.0 0 0 ? S 09:10 0:00 [watchdog/0]
root 7 0.1 0.0 0 0 ? S 09:10 0:02 [events/0]
root 8 0.0 0.0 0 0 ? S 09:10 0:00 [cgroup]
root 9 0.0 0.0 0 0 ? S 09:10 0:00 [khelper]
root 10 0.0 0.0 0 0 ? S 09:10 0:00 [netns]
root 11 0.0 0.0 0 0 ? S 09:10 0:00 [async/mgr]
root 12 0.0 0.0 0 0 ? S 09:10 0:00 [pm]
root 13 0.0 0.0 0 0 ? S 09:10 0:00 [sync_supers]
root 14 0.0 0.0 0 0 ? S 09:10 0:00 [bdi-default]
root 15 0.0 0.0 0 0 ? S 09:10 0:00 [kintegrityd/0]
root 16 0.0 0.0 0 0 ? S 09:10 0:00 [kblockd/0]
root 17 0.0 0.0 0 0 ? S 09:10 0:00 [kacpid]
root 18 0.0 0.0 0 0 ? S 09:10 0:00 [kacpi_notify]
root 19 0.0 0.0 0 0 ? S 09:10 0:00 [kacpi_hotplug]
root 20 0.0 0.0 0 0 ? S 09:10 0:00 [ata_aux]
root 21 0.0 0.0 0 0 ? S 09:10 0:00 [ata_sff/0]
root 22 0.0 0.0 0 0 ? S 09:10 0:00 [ksuspend_usbd]
root 23 0.0 0.0 0 0 ? S 09:10 0:00 [khubd]
root 24 0.0 0.0 0 0 ? S 09:10 0:00 [kseriod]
root 25 0.0 0.0 0 0 ? S 09:10 0:00 [md/0]
root 26 0.0 0.0 0 0 ? S 09:10 0:00 [md_misc/0]
root 27 0.0 0.0 0 0 ? S 09:10 0:00 [linkwatch]
root 28 0.0 0.0 0 0 ? S 09:10 0:00 [khungtaskd]
root 29 0.0 0.0 0 0 ? S 09:10 0:00 [kswapd0]
root 30 0.0 0.0 0 0 ? SN 09:10 0:00 [ksmd]
root 31 0.0 0.0 0 0 ? SN 09:10 0:00 [khugepaged]
root 32 0.0 0.0 0 0 ? S 09:10 0:00 [aio/0]
root 33 0.0 0.0 0 0 ? S 09:10 0:00 [crypto/0]
root 38 0.0 0.0 0 0 ? S 09:10 0:00 [kthrotld/0]
root 39 0.0 0.0 0 0 ? S 09:10 0:00 [pciehpd]
root 41 0.0 0.0 0 0 ? S 09:10 0:00 [kpsmoused]
root 42 0.0 0.0 0 0 ? S 09:10 0:00 [usbhid_resumer]
root 72 0.0 0.0 0 0 ? S 09:10 0:00 [kstriped]
root 147 0.0 0.0 0 0 ? S 09:10 0:00 [scsi_eh_0]
root 148 0.0 0.0 0 0 ? S 09:10 0:00 [scsi_eh_1]
root 155 0.0 0.0 0 0 ? S 09:10 0:00 [mpt_poll_0]
root 156 0.0 0.0 0 0 ? S 09:10 0:00 [mpt/0]
root 157 0.0 0.0 0 0 ? S 09:10 0:00 [scsi_eh_2]
root 279 0.0 0.0 0 0 ? S 09:10 0:00 [flush-8:0]
root 285 0.0 0.0 0 0 ? S 09:10 0:00 [jbd2/sda5-8]
root 286 0.0 0.0 0 0 ? S 09:10 0:00 [ext4-dio-unwrit]
root 376 0.1 0.0 11616 1716 ? S<s 09:10 0:01 /sbin/udevd -d
root 716 0.0 0.0 0 0 ? S 09:10 0:00 [vmmemctl]
root 915 0.0 0.0 0 0 ? S 09:10 0:00 [jbd2/sda1-8]
root 916 0.0 0.0 0 0 ? S 09:10 0:00 [ext4-dio-unwrit]
root 917 0.0 0.0 0 0 ? S 09:10 0:00 [jbd2/sda2-8]
root 918 0.0 0.0 0 0 ? S 09:10 0:00 [ext4-dio-unwrit]
root 1010 0.0 0.0 0 0 ? S 09:10 0:00 [kauditd]
root 1212 0.0 0.0 27640 840 ? S<sl 09:10 0:00 auditd
root 1237 0.0 0.0 251200 1684 ? Sl 09:10 0:00 /sbin/rsyslogd -i /var/run/syslogd.pid -c 5
rpc 1280 0.0 0.0 18976 904 ? Ss 09:10 0:00 rpcbind
dbus 1295 0.0 0.0 32076 1632 ? Ssl 09:10 0:00 dbus-daemon --system
root 1306 0.0 0.2 82740 4440 ? Ss 09:10 0:00 NetworkManager --pid-file=/var/run/NetworkManager/NetworkManager.pi
root 1312 0.0 0.1 58064 2464 ? S 09:10 0:00 /usr/sbin/modem-manager
rpcuser 1325 0.0 0.0 23348 1372 ? Ss 09:10 0:00 rpc.statd
root 1380 0.0 0.0 44968 696 ? Ss 09:10 0:00 /usr/sbin/wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf
root 1381 0.0 0.1 188872 3340 ? Ss 09:10 0:00 cupsd -C /etc/cups/cupsd.conf
root 1398 0.0 0.0 4080 664 ? Ss 09:11 0:00 /usr/sbin/acpid
68 1407 0.0 0.2 39000 5336 ? Ssl 09:11 0:00 hald
root 1408 0.0 0.0 20328 1196 ? S 09:11 0:00 hald-runner
root 1450 0.0 0.0 22448 1096 ? S 09:11 0:00 hald-addon-input: Listening on /dev/input/event2 /dev/input/event0
68 1461 0.0 0.0 17936 1048 ? S 09:11 0:00 hald-addon-acpi: listening on acpid socket /var/run/acpid.socket
root 1481 0.0 0.0 385728 1784 ? Ssl 09:11 0:00 automount --pid-file /var/run/autofs.pid
root 1506 0.0 0.0 66140 1248 ? Ss 09:11 0:00 /usr/sbin/sshd
root 1586 0.0 0.1 80808 3396 ? Ss 09:11 0:00 /usr/libexec/postfix/master
postfix 1594 0.0 0.1 80888 3380 ? S 09:11 0:00 pickup -l -t fifo -u
postfix 1595 0.0 0.1 80956 3420 ? S 09:11 0:00 qmgr -l -t fifo -u
root 1610 0.0 0.0 110328 956 ? Ss 09:11 0:00 /usr/sbin/abrtd
root 1618 0.2 0.0 116840 1388 ? Ss 09:11 0:03 crond
root 1629 0.0 0.0 21076 492 ? Ss 09:11 0:00 /usr/sbin/atd
root 1641 0.0 0.0 61864 616 ? Ss 09:11 0:00 /usr/sbin/certmonger -S -p /var/run/certmonger.pid
root 1649 0.0 0.1 133944 2188 ? Ssl 09:11 0:00 /usr/sbin/gdm-binary -nodaemon
root 1654 0.0 0.0 4064 540 tty2 Ss+ 09:11 0:00 /sbin/mingetty /dev/tty2
root 1656 0.0 0.0 4064 544 tty3 Ss+ 09:11 0:00 /sbin/mingetty /dev/tty3
root 1658 0.0 0.0 4064 544 tty4 Ss+ 09:11 0:00 /sbin/mingetty /dev/tty4
root 1660 0.0 0.0 4064 544 tty5 Ss+ 09:11 0:00 /sbin/mingetty /dev/tty5
root 1668 0.0 0.0 4064 540 tty6 Ss+ 09:11 0:00 /sbin/mingetty /dev/tty6
root 1669 0.0 0.1 12536 2812 ? S< 09:11 0:00 /sbin/udevd -d
root 1670 0.0 0.1 12536 2812 ? S< 09:11 0:00 /sbin/udevd -d
root 1685 0.0 0.1 164576 3056 ? Sl 09:11 0:00 /usr/libexec/gdm-simple-slave --display-id /org/gnome/DisplayManage
root 1688 0.2 1.1 151336 22768 tty1 Ss+ 09:11 0:03 /usr/bin/Xorg :0 -nr -verbose -audit 4 -auth /var/run/gdm/auth-for-
root 1704 0.0 0.1 577596 3256 ? Sl 09:11 0:00 /usr/sbin/console-kit-daemon --no-daemon
gdm 1774 0.0 0.0 20040 656 ? S 09:11 0:00 /usr/bin/dbus-launch --exit-with-session
gdm 1775 0.0 0.0 31776 1288 ? Ssl 09:11 0:00 /bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
gdm 1777 0.0 0.4 268844 7880 ? Ssl 09:11 0:00 /usr/bin/gnome-session --autostart=/usr/share/gdm/autostart/LoginWi
root 1780 0.0 0.1 49876 2704 ? S 09:11 0:00 /usr/libexec/devkit-power-daemon
gdm 1784 0.0 0.2 133480 5528 ? S 09:11 0:00 /usr/libexec/gconfd-2
root 1797 0.0 0.2 99872 4000 ? Ss 09:11 0:00 sshd: root@pts/0
gdm 1801 0.0 0.2 120392 4440 ? S 09:11 0:00 /usr/libexec/at-spi-registryd
gdm 1805 0.1 0.6 356620 12740 ? Ssl 09:11 0:01 /usr/libexec/gnome-settings-daemon --gconf-prefix=/apps/gdm/simple-
gdm 1807 0.0 0.1 368768 3012 ? Ssl 09:11 0:00 /usr/libexec/bonobo-activation-server --ac-activate --ior-output-fd
gdm 1816 0.0 0.0 135180 1896 ? S 09:11 0:00 /usr/libexec/gvfsd
gdm 1817 0.0 0.5 294708 9912 ? S 09:11 0:00 metacity
gdm 1818 0.0 0.3 247964 7388 ? S 09:11 0:00 /usr/libexec/polkit-gnome-authentication-agent-1
gdm 1819 0.0 0.6 295284 12264 ? S 09:11 0:00 plymouth-log-viewer --icon
gdm 1820 0.0 0.4 273400 8652 ? S 09:11 0:00 gnome-power-manager
gdm 1821 0.0 0.8 390244 15772 ? S 09:11 0:00 /usr/libexec/gdm-simple-greeter
root 1824 0.0 0.2 52580 4196 ? S 09:11 0:00 /usr/libexec/polkit-1/polkitd
gdm 1833 0.3 0.2 427152 4180 ? S<sl 09:11 0:04 /usr/bin/pulseaudio --start --log-target=syslog
rtkit 1835 0.0 0.0 168456 1200 ? SNl 09:11 0:00 /usr/libexec/rtkit-daemon
root 1842 0.0 0.1 141648 2076 ? S 09:11 0:00 pam: gdm-password
root 1848 0.0 0.0 108344 1792 pts/0 Ss 09:12 0:00 -bash
root 1975 3.0 0.0 110248 1140 pts/0 R+ 09:32 0:00 ps aux
[root@weekend110 ~]#
top 對linux系統進行動態監控,按q鍵或ctrl +c 退出
以top - 09:39:26 up 29 min, 1 user, load average: 0.00, 0.00, 0.00為例
top - 09:39:26 up 29 min,說的是top命令在09:39:26啟動,并持續29min
1 user,說的是系統中共有一個用戶在登錄
load average: 0.00, 0.00, 0.00,說的是系統負載的平均值
以Tasks: 108 total, 1 running, 107 sleeping, 0 stopped, 0 zombie為例
108total,是結果顯示系統中共有108個進程,目前只有1個進程正在運行,有107個進程處于睡眠狀態,沒有進程被終止,沒有進程被僵死。
以Cpu(s): 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st為例
top顯示運行在用戶模式和內核模式的進程(ni)所占的CPU百分比,以及在系統空間(id)時所占的CPU空間時間百分比,wa(iowait)表示沒有進程在CPU上運行時處理器等待I/O完成的時間百分比,hi和si表示硬件與軟件中斷所花費的CPU時間的百分比。
以Mem: 1906552k total, 303492k used, 1603060k free, 25744k buffers為例。這里顯示是系統物理內存的使用情況
依次表示系統的總內存,已使用的內存、空閑的內存、緩沖區使用的內存
Swap: 3128464k total, 0k used, 3128464k free, 99456k cached。這里顯示是系統交換分區的信息
依次表示交換分區的總量、使用量、空閑和用于內核緩存的內存量
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 。這里顯示是系統進程信息
NI表示進程的優先級,SHR表示進程使用的共享內存的數量,TIME+表示自進程啟動以來所使用的CPU時間量
[root@weekend110 ~]# top
top - 09:39:26 up 29 min, 1 user, load average: 0.00, 0.00, 0.00
Tasks: 108 total, 1 running, 107 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 1906552k total, 303492k used, 1603060k free, 25744k buffers
Swap: 3128464k total, 0k used, 3128464k free, 99456k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1987 root 20 0 15036 1224 944 R 0.3 0.1 0:00.29 top
1 root 20 0 19356 1540 1228 S 0.0 0.1 0:03.31 init
2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
3 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
4 root 20 0 0 0 0 S 0.0 0.0 0:00.01 ksoftirqd/0
5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
6 root RT 0 0 0 0 S 0.0 0.0 0:00.02 watchdog/0
7 root 20 0 0 0 0 S 0.0 0.0 0:02.67 events/0
8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cgroup
9 root 20 0 0 0 0 S 0.0 0.0 0:00.01 khelper
10 root 20 0 0 0 0 S 0.0 0.0 0:00.00 netns
11 root 20 0 0 0 0 S 0.0 0.0 0:00.00 async/mgr
12 root 20 0 0 0 0 S 0.0 0.0 0:00.00 pm
其實,除了,使用命令來監控linux系統的進程外,自帶了一個圖形系統監控工具。即System Monitor。在終端上輸入gnome-system-monitor或Applications->System Tools->System Monitor。類似于windows系統的任務管理器。
[root@weekend110 ~]gnome -system-monitor
或者
進程創建和終止
對于Linux系統啊,只要輸入一條指令并執行該指令,就開啟了一個新的進程。可以在指令后面使用“&”來開啟一個后臺進程。
什么是后臺進程?
所謂后臺進程,就是進程在運行后并未顯示進程執行的過程,且直接返回終端提示符、不占用終端窗口的進程。
什么時候用后臺進程?
當執行一個比較耗時的進程且不需要用戶進程交互時,可以考慮選擇在后臺進程該進程。
[root@weekend110 ~]# top &
[1] 2493
[root@weekend110 ~]# ^C
[1]+ Stopped top
[root@weekend110 ~]#
進程的終止,使用kill命令將其終止,而在使用kill之前,需要知道該進程ID,即PID,可以使用ps命令。
如下,演示
[root@weekend110 ~]# man ls 運行man命令
LS(1) User Commands LS(1)
NAME
ls - list directory contents
SYNOPSIS
ls [OPTION]... [FILE]...
DESCRIPTION
List information about the FILEs (the current directory by default). Sort entries alphabetically if none of
-cftuvSUX nor --sort.
Mandatory arguments to long options are mandatory for short options too.
-a, --all
do not ignore entries starting with .
-A, --almost-all
do not list implied . and ..
--author
[root@weekend110 ~]# pgrep -l man 使用pgrep來獲取處于運行狀態的man命令的PID
2542 man
kill -1 掛起
kill -2 終端
kill -9 終止
kill -15 終止
kill -19 暫停
也可,在圖形界面里,對進程的終止。
總結
- 上一篇: 家庭幸福(家庭幸福的经典语句)
- 下一篇: Apache Griffin安装