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.