Sample Header Ad - 728x90

How to find one of multiple processes with the same name using pgrep (or another tool)?

-2 votes
1 answer
618 views
I have several bash scripts running. The only thing that differs between them is the pid. I want to write a script like this that only monitors one specific bash process and exclude any daughter processes. I have seen this question but in that case the process names differs and you just have to write a precise regular expression. Currently, if I do % pgrep bash 40583 47095 48133 49244 and if I do % pgrep -P 47095 47099 50151 I want to do something like % pgrep bash -P 47095 and then get the result 47095 # (i.e. no daughter processes) or an empty return value if 47095 no longer exists. How can this be achieved? The answer doesn't need to be based on pgrep, what is important is that it only returns one line if the process is running and nothing if there is no such process.
Asked by d-b (2047 rep)
Jul 24, 2023, 12:57 PM
Last activity: Jul 25, 2023, 04:43 AM