欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

【Do家】Linux下提取并记录某个应用的进程号 linuxpspid 

程序员文章站 2022-05-26 10:18:57
...
样例如下:

#!/bin/sh

BINDIR=`dirname $0`

#echo $BINDIR;

nohup $BINDIR/startYourProcessName -p > /dev/null &



echo next step is recording pid

sleep 3;

# write the pid of yourProcessName to file

ps -ef|grep java |grep yourProcessName |awk '{print $2, $9}' > ../logs/random;

# define domain_name

domain_name=`pwd`;

#echo $domain_name;

#

while read line

do

temp_line=$line"/bin";

#echo $temp_line;

echo $temp_line |grep -q $domain_name;

if [ $? -eq 0 ]

then

    echo $line |awk '{print $1}' > ../logs/yourProcessName.pid;

fi

:

done < ../logs/random



rm -f ../logs/random;

echo finished to recording pid

exit;
相关标签: linux ps pid