[英]Find out if process / file is running linux
我想检查一个进程是否正在运行。 我一直在尝试
ps -C /path/file
并得到以下响应:
PID TTY TIME CMD
如果我做
pgrep php
我得到了正在运行的php进程的列表,但只有PID。
是否有可能
操作系统: Ubuntu 14.04 LTS
从很长一段时间以来,我一直在寻找这个,尝试了我在SO上发现的所有可能性,但是无法弄清楚如何做到最好。
“确定我指定的文件的PID。”
lsof | grep <file> | awk '{print $2}'
“如果输入PID,则获取文件名。”
lsof | grep <PID>
lsof | grep <PID> | awk '{print $NF}'
“在文件中获取所有正在运行的进程PID,以在以后的脚本中使用它。”
ps x | awk '{print $1}' > pid-list.txt # PIDs of all processes run by current user
ps ax | awk '{print $1}' > pid-list.txt # PIDs of all processes run by all users
ps aux | grep <the-name-of-the-process>
ps aux | grep <the-name-of-the-process>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.