指令 ipcs 可產生一份使用中的 IPC 資源清單:
------ Shared Memory Segments -------- key shmid owner perms bytes nattch status 0x00000000 58261504 tux 600 393216 2 dest 0x00000000 58294273 tux 600 196608 2 dest 0x00000000 83886083 tux 666 43264 2 0x00000000 83951622 tux 666 192000 2 0x00000000 83984391 tux 666 282464 2 0x00000000 84738056 root 644 151552 2 dest ------ Semaphore Arrays -------- key semid owner perms nsems 0x4d038abf 0 tux 600 8 ------ Message Queues -------- key msqid owner perms used-bytes messages
指令 ps 會產生一份程序清單。大部份的參數在寫入時都不可包含減號。請參閱 ps --help 取得簡短說明,或是參閱 man 頁面取得詳細的說明。
若要列出包含使用者和指令行資訊的所有程序,請使用 ps axu:
tux@mercury:~> ps axu USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.0 696 272 ? S 12:59 0:01 init [5] root 2 0.0 0.0 0 0 ? SN 12:59 0:00 [ksoftirqd root 3 0.0 0.0 0 0 ? S< 12:59 0:00 [events [...] tux 4047 0.0 6.0 158548 31400 ? Ssl 13:02 0:06 mono-best tux 4057 0.0 0.7 9036 3684 ? Sl 13:02 0:00 /opt/gnome tux 4067 0.0 0.1 2204 636 ? S 13:02 0:00 /opt/gnome tux 4072 0.0 1.0 15996 5160 ? Ss 13:02 0:00 gnome-scre tux 4114 0.0 3.7 130988 19172 ? SLl 13:06 0:04 sound-juic tux 4818 0.0 0.3 4192 1812 pts/0 Ss 15:59 0:00 -bash tux 4959 0.0 0.1 2324 816 pts/0 R+ 16:17 0:00 ps axu
若要檢查有多少個 sshd 程序正在執行,請一起使用 -p
選項和 pidof 指令來列出指定程序的程序 ID。
tux@mercury:~> ps -p `pidof sshd` PID TTY STAT TIME COMMAND 3524 ? Ss 0:00 /usr/sbin/sshd -o PidFile=/var/run/sshd.init.pid 4813 ? Ss 0:00 sshd: tux [priv] 4817 ? R 0:00 sshd: tux@pts/0
程序清單可依照您的需要採用格式。選項 -L
會傳回所有關鍵字的清單。輸入下列指令,發出一份依記憶體使用排序的程序清單:
tux@mercury:~> ps ax --format pid,rss,cmd --sort rss PID RSS CMD 2 0 [ksoftirqd/0] 3 0 [events/0] 4 0 [khelper] 5 0 [kthread] 11 0 [kblockd/0] 12 0 [kacpid] 472 0 [pdflush] 473 0 [pdflush] [...] 4028 17556 nautilus --no-default-window --sm-client-id default2 4118 17800 ksnapshot 4114 19172 sound-juicer 4023 25144 gnome-panel --sm-client-id default1 4047 31400 mono-best --debug /usr/lib/beagle/Best.exe --autostarted 3973 31520 mono-beagled --debug /usr/lib/beagle/BeagleDaemon.exe --bg --aut
指令 pstree 會產生一份樹狀程序清單:
tux@mercury:~> pstree init-+-NetworkManagerD |-acpid |-3*[automount] |-cron |-cupsd |-2*[dbus-daemon] |-dbus-launch |-dcopserver |-dhcpcd |-events/0 |-gpg-agent |-hald-+-hald-addon-acpi | `-hald-addon-stor |-kded |-kdeinit-+-kdesu---su---kdesu_stub---yast2---y2controlcenter | |-kio_file | |-klauncher | |-konqueror | |-konsole-+-bash---su---bash | | `-bash | `-kwin |-kdesktop---kdesktop_lock---xmatrix |-kdesud |-kdm-+-X | `-kdm---startkde---kwrapper [...]
參數 -p
會將程序 ID 新增至指定的名稱。若要同時顯示指令行,請使用 -a
參數:
指令 top (即「程序表 (table of processes)」的縮寫) 會顯示一個程序清單,每隔兩秒自動更新一次。若要終止程式,請按 Q。參數 -n 1
會在程序清單顯示一次之後,終止程式。以下是 top -n 1 指令的輸出範例:
tux@mercury:~> top -n 1 top - 17:06:28 up 2:10, 5 users, load average: 0.00, 0.00, 0.00 Tasks: 85 total, 1 running, 83 sleeping, 1 stopped, 0 zombie Cpu(s): 5.5% us, 0.8% sy, 0.8% ni, 91.9% id, 1.0% wa, 0.0% hi, 0.0% si Mem: 515584k total, 506468k used, 9116k free, 66324k buffers Swap: 658656k total, 0k used, 658656k free, 353328k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1 root 16 0 700 272 236 S 0.0 0.1 0:01.33 init 2 root 34 19 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/0 3 root 10 -5 0 0 0 S 0.0 0.0 0:00.27 events/0 4 root 10 -5 0 0 0 S 0.0 0.0 0:00.01 khelper 5 root 10 -5 0 0 0 S 0.0 0.0 0:00.00 kthread 11 root 10 -5 0 0 0 S 0.0 0.0 0:00.05 kblockd/0 12 root 20 -5 0 0 0 S 0.0 0.0 0:00.00 kacpid 472 root 20 0 0 0 0 S 0.0 0.0 0:00.00 pdflush 473 root 15 0 0 0 0 S 0.0 0.0 0:00.06 pdflush 475 root 11 -5 0 0 0 S 0.0 0.0 0:00.00 aio/0 474 root 15 0 0 0 0 S 0.0 0.0 0:00.07 kswapd0 681 root 10 -5 0 0 0 S 0.0 0.0 0:00.01 kseriod 839 root 10 -5 0 0 0 S 0.0 0.0 0:00.02 reiserfs/0 923 root 13 -4 1712 552 344 S 0.0 0.1 0:00.67 udevd 1343 root 10 -5 0 0 0 S 0.0 0.0 0:00.00 khubd 1587 root 20 0 0 0 0 S 0.0 0.0 0:00.00 shpchpd_event 1746 root 15 0 0 0 0 S 0.0 0.0 0:00.00 w1_control 1752 root 15 0 0 0 0 S 0.0 0.0 0:00.00 w1_bus_master1 2151 root 16 0 1464 496 416 S 0.0 0.1 0:00.00 acpid 2165 messageb 16 0 3340 1048 792 S 0.0 0.2 0:00.64 dbus-daemon 2166 root 15 0 1840 752 556 S 0.0 0.1 0:00.01 syslog-ng 2171 root 16 0 1600 516 320 S 0.0 0.1 0:00.00 klogd 2235 root 15 0 1736 800 652 S 0.0 0.2 0:00.10 resmgrd 2289 root 16 0 4192 2852 1444 S 0.0 0.6 0:02.05 hald 2403 root 23 0 1756 600 524 S 0.0 0.1 0:00.00 hald-addon-acpi 2709 root 19 0 2668 1076 944 S 0.0 0.2 0:00.00 NetworkManagerD 2714 root 16 0 1756 648 564 S 0.0 0.1 0:00.56 hald-addon-stor
如果您在 top 正在執行時按 F,這時會出現一個功能表,供您用來變更輸出格式。
參數 -U
只會監視與特定使用者有關的程序。以使用者的使用者 ID 來取代 UID
UID
。top -U `id -u` 指令會根據使用者名稱傳回使用者的 UID,並顯示其程序。