【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;
#!/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;