shell:判断一个进程是否存在 - dato0123 - ITeye技术网站


Javascript代码
  1. #test.sh  
  2. #!/bin/sh  
  3. pid=`ps -ef | grep -v grep | grep -v "test.sh" | grep $1 | sed -n  '1P' | awk '{print $2}'`  
  4. if [ -z $pid ] ; then  
  5.     echo "no this process"  
  6. else  
  7.     echo $pid  
  8. fi  


例:
查询是否存在hello进程
#./test.sh hello
如果存在hello进程,会输出PID
不存在会输出 no this process

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-05
  • 2021-12-07
  • 2022-12-23
猜你喜欢
  • 2021-08-02
  • 2022-12-23
  • 2022-12-23
  • 2021-12-22
  • 2022-12-23
  • 2021-09-09
  • 2022-12-23
相关资源
相似解决方案