Linux command to check if a shell script is running or not

前端 未结 9 2130
栀梦
栀梦 2020-12-04 14:55

What is the linux command to find if a process say aa.sh is running or not. ps command does not seem to work and it does not show the shell script names.

Please advi

相关标签:
9条回答
  • 2020-12-04 15:18

    Give an option to ps to display all the processes, an example is:

    ps -A | grep "myshellscript.sh"
    

    Check http://www.cyberciti.biz/faq/show-all-running-processes-in-linux/ for more info

    And as Basile Starynkevitch mentioned in the comment pgrep is another solution.

    0 讨论(0)
  • 2020-12-04 15:20

    Check this

    ps aux | grep "aa.sh"
    
    0 讨论(0)
  • 2020-12-04 15:26
    pgrep -f aa.sh 
    

    To do something with the id, you pipe it. Here I kill all its child tasks.

    pgrep aa.sh | xargs pgrep -P ${} | xargs kill
    

    If you want to execute a command if the process is running do this

    pgrep aa.sh && echo Running
    
    0 讨论(0)
提交回复
热议问题