我有一个命令(程序),我想运行nohup和背景。 喜欢
nohup command > logfile.txt &
如何找出进程ID? 我想能够在一个文件中写入进程ID,稍后阅读并以编程方式终止进程。
在你的脚本中:
nohup command > logfile.txt & echo $! > /var/run/command.pid
你可以使用$! 。 在bash文档中引用。
您可以使用ps和grep在进程列表中查找进程,然后awkparsing输出并find实际的PID:
ps -ef | grep -v grep | grep YOUR_PROCESS_NAME | awk '{ print $2 }'
你可以尝试:
ps aux | grep -v grep | grep 程序名称
这将检查正在运行的进程,grep的程序名称,但排除grep本身。