SidSethupathi
SidSethupathi

Reputation: 63

script has two running processes with different PIDs (always a difference of 4)

I have a ksh script that calls other scripts. The initial script only makes one call to the second script. However, if I do "ps axwww | grep full_script_name | grep -v grep", it shows 2 instances of the second script, both with different PIDs. And the PIDs are always 4 numbers off from each other (eg 22089 and 22093).

Why is this happening?

Upvotes: 1

Views: 379

Answers (1)

twalberg
twalberg

Reputation: 62479

First off, it won't always be 4 off, because eventually it will run into some PIDs that are still allocated. But this is probably the scenario, or at least close to it:

  • Start script.ksh - get PID 42
  • script.ksh calls an external program, which gets PID 43, then exits and returns control to the script
  • script.ksh calls a second external program, which gets PID 44
  • script.ksh calls a third external program, getting PID 45
  • script.ksh calls child-script.ksh, which gets PID 46, and hangs around while you run ps

"External programs" are numerous - everything from ls to awk, sed, perl, sort......

Upvotes: 1

Related Questions