English 中文(简体)
有没有办法知道 发射程序是什么样吗?
原标题:is there any way to know the pid of a launched program?
  • 时间:2012-05-24 11:55:27
  •  标签:
  • bash

如果我在孩子的时候 推出一个碎纸剧本 我可以用美元 将它给父母

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 &

那只叮当是什么?

(我只希望我表达我的自我正确... 我的英语不是最好的)

PS,我在找一个简单而干净的解决方案, 我可以想象到一些东西,比如:

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

但也太复杂了, 即使我用开关来个性化, 开关不干净,

最佳回答

变量 $! 拥有您上次启动的背景进程的 PID 。

问题回答

执行您想要的 PID 命令后, 请使用此命令 : < code>$! 。 这意味着, 虽然您需要在命令后使用 ampersand () 来启动背景操作 。 例如 :

my_command & CMDPID=$!
echo "$CMDPID"




相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

Bash usage of vi or emacs

From a programming standpoint, when you set the bash shell to use vi or emacs via set -o vi or set -o emacs What is actually going on here? I ve been reading a book where it claims the bash shell ...

Dynamically building a command in bash

I am construcing a command in bash dynamically. This works fine: COMMAND="java myclass" ${COMMAND} Now I want to dynamically construct a command that redirectes the output: LOG=">> myfile.log ...

Perform OR on two hash outputs of sha1sum

I want perform sha1sum file1 and sha1sum file2 and perform bitwise OR operation with them using bash. Output should be printable i.e 53a23bc2e24d039 ... (160 bit) How can I do this? I know echo $(( ...

Set screen-title from shellscript

Is it possible to set the Screen Title using a shell script? I thought about something like sending the key commands ctrl+A shift-A Name enter I searched for about an hour on how to emulate ...

热门标签