- What is a process?
A process is a running instance of a launched, executable program.
- Process states
- Listing processes
The ps command is used for listing current processes.
# ps -l
只能查閱自己 bash 程序
# ps aux
可以查閱所有系統運作的程序
# ps j
顯示 job information
- Jobs and sessions
Job control is a command shell feature allowing a single shell instance to run and manage multiple commands.
A foreground process is a command running in a terminal window.
A process session is created when a terminal or console first opens.
A background process is started without a controlling terminal because it has no need for terminal interaction.
- Running jobs in the background
在 command line 最後加上 & 符號,即可讓指令在背景執行
另外,可用 jobs 指令查詢背景執行的工作
# jobs [-lrs]
-l :除了列出 job number 與指令串之外,同時列出 PID 的號碼
-r :僅列出正在背景當中執行 ( run ) 的工作
-s :僅列出正在背景當中暫停 (stop) 的工作
若想將工作移至前景執行,可使用 fg 指令
# fg %job number
將工作移至前景執行
- Process control using signals
# kill -l
列出目前 kill 能夠使用的 signal PID
# kill -signal %job number | PID
將 signal 傳送給某個工作 (%job number) 或者是某個 PID
# killall -signal command_pattern
將系統當中所有以某個指令名稱啟動的程序全部刪除
另外也可使用 pkill 指令來一次性刪除多個程序,有點類似 killall 的功能,不過 pkill 的參數較多,可以更精確去刪除指定程序
# pkill -SIGKILL -u bob
強制結束由使用者 bob 所執行的程序
# pstree -p
查詢程序相關性,以樹狀表示,-p 會同時列出每個 process 的 PID
- Logging users out administratively
The w command views users currently logged into the system and their cumulative activities.
Remote users display their connecting system name in the FROM column when using the -f option.
- Load average
It refers to the three displayed values of system activity data averaged for the last 1 ,5 ,and 15 minutes.
# uptime
觀察系統啟動時間與工作負載
- Real-time process monitoring
# top
可以持續偵測程序運作的狀態
Process state (S) displays as:
• D = Uninterruptable Sleeping
• R = Running or Runnable
• S = Sleeping
• T = Stopped or Traced
• Z = Zombie