Home > other >  Linux ps aux with grep check for specific PHP process ID
Linux ps aux with grep check for specific PHP process ID

Time:04-27

I'm trying to figure out whether a PHP process is running or not using the ps aux command and passing grep to it, for instance:

I need it to return and tell me whether a process ID on php is running or not but whenever I try the following I always seem to get a result where the result is appending 1234 at the end, what am I missing?

ps aux | grep 'php|1234'

enter image description here

CodePudding user response:

Suggesting pgrep command instead of ps aux

pgrep -af "php"

The reason your get always one line:

  1. php process is not matched with grep 'php|123123123'

  2. ps aux list the grep command you submitted and the grep command match itself

  3. maybe you meant grep -E 'php|123123123' to match php or 123123123

CodePudding user response:

The solution I've come across thanks to a user above is to do:

ps aux | grep '123456' | grep 'grep' -v

Where 123456 would be the process ID

  • Related