有什么办法可以知道已启动程序的pid? [英] is there any way to know the pid of a launched program?

查看:53
本文介绍了有什么办法可以知道已启动程序的pid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我还是一个孩子启动bash脚本,则可以使用$$将其自己的pid传递给父对象.

if I launch a bash script as a child, I can pass its own pid to the parent by using $$.

有什么方法可以找到我从后台脚本启动的程序的pid 像:

Is there any way to find the pid of a program that I launch from a script in background like:

ping x.x.x.x &

该ping的pid是什么?

what's the pid of that ping ?

(我只是希望我能正确表达自己的意思……我的英语不是最好的)

(I just hope I expressed my self correctly ... my English is not the best)

PS.我正在寻找一个简单干净的解决方案,我可以想像像这样的东西:

PS. I'm looking for a simple and clean solution, I can imagine something like:

ping -t10000 -W10 x.x.x.x &
then
ps ax | grep 'ping -t10000 -W10 x.x.x.x'$

但是太复杂了,即使我使用开关对其进行个性化设置也不干净,它可能会捕获系统中的其他进程

but is too complicated, also even that I used switches to personalize it is not clean, it may catch another processes in the system

推荐答案

变量$!具有您启动的上一个后台进程的PID.

The variable $! has the PID of the last background process you started.

这篇关于有什么办法可以知道已启动程序的pid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆