linux查看进程与线程数

时间:2023-03-08 22:23:30

1. 查看进程:ps -ef 或 ps -aux

得到进程的pid:
如:
ps -ef | grep process_name | grep -v "grep" | awk '{print $2}'

2.根据进程号进行查询:

# pstree -p 进程号

# top -Hp 进程号

3.根据进程名字进行查询:

# pstree -p `ps -e | grep server | awk '{print $1}'`

# pstree -p `ps -e | grep server | awk '{print $1}'` | wc -l

4.查看线程数

需要得到线程的PID

查看进程的所有线程
# ps mp -o THREAD,tid
USER %CPU PRI SCNT WCHAN USER SYSTEM TID
root 0.0 - - - - - -
root 0.0 - - - -
root 0.0 - - - -
root 1.0 - - - -
root 0.0 - futex_ - -
root 0.0 - - -
root 0.0 - - -
root 0.0 - - -
root 0.0 - - -
root 0.0 - - -
root 0.0 - - -
root 0.0 - - - 查看所有子进程:
# pstree -p
agent_executor()─┬─tar()───gzip()
├─{agent_executor}()
├─{agent_executor}()
├─{agent_executor}()
├─{agent_executor}()
├─{agent_executor}()
├─{agent_executor}()
├─{agent_executor}()
├─{agent_executor}()
├─{agent_executor}()
└─{agent_executor}()

5. 进程启动时间(运行多长时间)

ps -eo lstart 启动时间

ps -eo etime   运行多长时间.

ps -eo pid,lstart,etime | grep 5176

========================================ps aux 或 lax 输出的解释=========================
、ps aux 或 lax 输出的解释
au(x) 输出格式 :
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND USER: 进程所有者
PID: 进程ID
%CPU: 占用的 CPU 使用率
%MEM: 占用的内存使用率
VSZ: 占用的虚拟内存大小
RSS: 占用的内存大小
TTY: 终端的次要装置号码 (minor device number of tty)
STAT: 进程状态:
START: 启动进程的时间;
TIME: 进程消耗CPU的时间;
COMMAND:命令的名称和参数;