# ps [OPTION]...# OPTION STYLE: UNIX-style(-c), GNU-style(--dosomething), X-style(-dosomething), BSD-style(a)# a: 显示【所有用户】、【有 TTY】的进程# x: 无论有无 TTY# u: user-oriented output, 显示 USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND 信息# f: 使用树形结构(\_)格式化父子进程# --sort=[+|-NAME]... 根据 NAME 排序,+(升序,默认),-(降序), # e.g. ps faux --sort=uid,-user,+%cpu# -e, -A: 显示【所有用户】、【无论有无 TTY】的进程 # e.g. ps ax = ps -e# -f: 显示 UID PID PPID C STIME TTY TIME CMD# -H: 树形结构(空格)格式化父子进程ps -ef --sort=cmd# jobs [OPTION]...# -l —Lists the process IDs along with the normal output# -n —Displays information only about jobs that have changed status since the user was last notified of their status# -r —Restricts output to running jobs# -s —Restricts output to stopped jobs# fg [%N] # 使 job number 为 N 的进程变为【前台】进程(如果不传 %N, 则选择最近交互的 job)# bg [%N] # 使 job number 为 N 的进程变为【后台】进程(如果不传 %N, 则选择最近交互的 job)# 在后台运行任务# command & # 运行一个# command1 & command2 & command3 & # 运行多个# command1 & | command2 & command3 & # 运行2个(后台运行command1的输出重定向给在后台运行的command2,这算是一个进程)# cmd -x # 原本想加个 & 使 cmd 在后台运行,但是忘记了# 按 CTRL+Z, 使 cmd 挂起# bg # 使 current job 即 cmd -x,变为后台程序# shell 关闭后,jobs 也会结束# 除非 1. 使用 byobu# 2. 守护进程(daemon)