How can I investigates whether already running a program called /root/dodo/dodo

Posted on

Problem :

How can I investigates whether already running a program called /root/dodo/dodo?
But I need to run a scan directly from the program, which tests.
Thank you…

file /root/todo/todo

#!/bin/bash
if [ check run program /root/todo/todo ]
then
  exit
else
  #continued
fi

Solution :

you can check the process and see if there is a name like you indicated:

$ ps aux | grep "/root/dodo/dodo"

if you need to do test inside a bash script,

ps aux | grep -v "grep" | grep -q "/root/dodo/dodo"
if [ $? -eq 0 ]; then
   # do stuff if it is running
else
   # do stuff if it is not running
fi

If you want to know whether a program called /root/dodo/dodo is already running or not at the moment, use the following:

ps eaf | grep /root/dodo/dodo

It seems that you want to write a shell script which ensures that there is only one single instance (process) running it.

Then see this question and consider using lockfile(1)

The appropriate way to check whether one or more running processes match a string is pgrep. Never use ps | grep.

if pgrep bash >/dev/null; then 
   echo "found a bash process"
else 
   echo "didn't find a bash process"
fi

Leave a Reply

Your email address will not be published. Required fields are marked *