如何编写运行长时间运行的程序并将程序进程ID存储在单独文件中的Bash脚本?
我想要类似的东西
#!/bin/bash
exec long_running_tool
echo `ps af |grep "long_running_tool" |awk '$5 == "long_running_tool" {print $1}'` > pid_file
但是,准确地执行此操作将ps
在工具完成之后执行。
有没有一种方法来获取创建的进程的进程ID?
@ e-t172感谢您指出。然后我删除“ exec”。
—
DerMike 2011年
请参阅流程管理。
—
暂停,直到另行通知。
long_running_tool
进程替换。因此,exec永不返回,也永远不会到达以下行。见help exec
,execve(2)
。