Q1 : Recently, some operations scripts is deployed on machine-01, in order to monitor process alive in remote machines. This feature is done by periodly do following cmd:
ssh $ip "ps aux | grep $pattern " | grep -v 'grep' | wc -l
Although it works as I expect, it make mistake some times, which means the result of above cmd is 'empty'. By the way, i check the result by this cmd:
if [ "$nums" -lt 1 ]
Q2 : What's more, this operations scripts would create background-sub-process to run other sub-script, as amount of 60 in design. when I 'ps aux | grep xxx' to see if them were created as I expect, just found that a few lines have different PID with same CMD, which I would call 'ghost pid'. If these 'ghost pid' is sub-sub-process created by these background-sub-process, why they have same CMD?
This two facts hints me that I may not kown 'ps aux | grep xxx' well. Could anyone explain some for me?
after replace ps aux | grep xxx with pgrep. 'ghost pid' still happen. I hacked by double check for Q1. But still can't fix Q2. fig-1 is what my start sub-process log. fig-2 is what I got when period pgrep sub-process.