Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 当程序由nohup启动时,如何获取pid?_Linux_Bash - Fatal编程技术网

Linux 当程序由nohup启动时,如何获取pid?

Linux 当程序由nohup启动时,如何获取pid?,linux,bash,Linux,Bash,我的store_plus.py计划由以下人员启动: WORK_DIR=/usr/local/gdnsplus_reducecname SPOOL_DIR=$WORK_DIR/var/spool STORE_PLUS_SERVER="$WORK_DIR/bin/store_plus.py" /usr/bin/nohup /usr/bin/python $STORE_PLUS_SERVER 1>$SPOOL_DIR/store_plus_nohup.out 2>&1 &

我的store_plus.py计划由以下人员启动:

WORK_DIR=/usr/local/gdnsplus_reducecname
SPOOL_DIR=$WORK_DIR/var/spool
STORE_PLUS_SERVER="$WORK_DIR/bin/store_plus.py"
/usr/bin/nohup /usr/bin/python $STORE_PLUS_SERVER  1>$SPOOL_DIR/store_plus_nohup.out 2>&1 &
现在,我想得到store_plus.py的pid。我尝试了一种方法:

store_plus_prog="store_plus"
STORE_PID=`ps aux | grep $store_plus_prog | grep python | awk '{print $2}'`
如您所见,这种方法非常复杂,并且使用了一些管道。 因此,我想使用pidofpgrep命令

pidof store_plus.py

但是他们不能工作。请给我一些建议


谢谢。

我相信这会达到你想要的

pgrep -f store_plus.py
根据手册页:


-f:模式通常只与进程名匹配。设置-f时,将使用完整的命令行

你看不懂<代码>$吗?它是一个bash变量,用于存储上次创建的进程的PID。。。
pgrep -f store_plus.py