I am wondering is it possible to check if a specific file with a specific name is running? I see a lot of various cases that show PID's rather than a filename but would rather take a filename route. For instance lets say a file called test.php is being executed via PHP command (in this case lets just pretend this file is just an infinite loop just so the file remains running indefinitely). Is there any command that I can write out that will let me know that this particular file is currently being executed? If this is not doable can I see all PHP files that are currently being ran? Currently using Ubunutu 18.04 LTS
pgrep -f test.php
This will output the PID of your command.
ps aux | grep '[t]est\.php'
This will output the corresponding line of
Another option is using killall
killall -0 -q test.php && echo test.php is running
Despite the name of the command, the process is not killed.
#!/bin/sh processname='login' if [ "$(pgrep $processname)x" != "x" ] then echo $processname is running else echo $processname is NOT running fi
An alternate version that uses the exit status rather than the return value, and also uses a more compact syntax
#!/bin/sh processname='login' pgrep $processname > /dev/null test $? -eq 0 && echo "$processname is running" || echo "$processname is NOT running"