Quantcast
Channel: How to determine whether a process is running or not and make use it to make a conditional shell script? - Ask Ubuntu
Browsing latest articles
Browse All 15 View Live

Answer by ceremcem for How to determine whether a process is running or not...

None of the "simple" solutions worked for me because the binary I need to check is not installed system-wide, so I have to check with path, which in turn requires using ps -ef | grep approach:...

View Article



Answer by Bach Lien for How to determine whether a process is running or not...

## bash ## function to check if a process is alive and running: _isRunning() { ps -o comm= -C "$1" 2>/dev/null | grep -x "$1" >/dev/null 2>&1 } ## example 1: checking if "gedit" is running...

View Article

Answer by user7449824 for How to determine whether a process is running or...

#!/bin/bash while [ true ]; do # Endless loop. pid=`pgrep -x ${1}` # Get a pid. if [ -z $pid ]; then # If there is none, ${1} & # Start Param to background. else sleep 60 # Else wait. fi done

View Article

Answer by Wayne Workman for How to determine whether a process is running or...

I found that the accepted answer posted by @John Vrbanac did not work for me, and that the answer posted by @geirha doesn't answer the original question. John Vrbanac's solution didn't work to check if...

View Article

Answer by Dominic for How to determine whether a process is running or not...

isProcessRunning() { if [ $(pidof $1) > /dev/null ]; then retval='true'; else retval='false'; fi; echo $retval; } isProcessRunning geany true

View Article


Answer by Martin Monperrus for How to determine whether a process is running...

Using start-stop-daemon: /sbin/start-stop-daemon --background --make-pidfile --pidfile /tmp/foo.pid -S --startas /usr/bin/program -- arg1 arg2 It works as normal user.

View Article

Answer by yuvilio for How to determine whether a process is running or not...

Riffing on @rommel-cid's idea, you can use pidof with the || (||) to run a command if the process does not exist and && to run something if the process does exist, thus creating a quick...

View Article

Answer by Rommel Cid for How to determine whether a process is running or not...

I usually have a pidof -x $(basename $0) on my scripts to check if it's already running.

View Article


Answer by geirha for How to determine whether a process is running or not and...

Any solution that uses something like ps aux | grep abc or pgrep abc are flawed. Why? Because you are not checking if a specific process is running, you are checking if there are any processes running...

View Article


Answer by Zuul for How to determine whether a process is running or not and...

This is what I use: #!/bin/bash #check if abc is running if pgrep abc >/dev/null 2>&1 then # abc is running else # abc is not running fi In plain English: if 'pgrep' returns 0, the process is...

View Article

Answer by John Vrbanac for How to determine whether a process is running or...

A bash script to do something like that would look something like this: #!/bin/bash # Check if gedit is running # -x flag only match processes whose name (or command line if -f is # specified) exactly...

View Article

Answer by drake01 for How to determine whether a process is running or not...

First thing that came to my mind for your problem: ps aux | grep -i abc will show the details of the process if its running. You may match the number of lines or time for which its running and compare...

View Article

How to determine whether a process is running or not and make use it to make...

How can I determine if a process is running or not and then have a bash script execute some stuff based on that condition? For example: if process abc is running, do this if it is not running, do that.

View Article


Answer by Alberto Salvia Novella for How to determine whether a process is...

By pid:pgrep [pid] >/dev/nullBy name:pgrep -u [user] -x [name] >/dev/null"-x" means "exact match".

View Article
Browsing latest articles
Browse All 15 View Live


Latest Images