Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在我的脚本中,我正在执行cat,然后尝试grep获取进程 ID。
cat
grep
我用这个:
ps | grep -e \'cat$\' | cut -d\' \' -f2 | head -n 1
但它没有返回任何东西。
当您在 shell 中启动后台进程时,program &您可以通过$!.
program &
$!
例如:
bash-4.2.37$ cat & [1] 9664 bash-4.2.37$ CAT_PID=$! ...time passes... bash-4.2.37$ echo $CAT_PID 9664