Bash subprocess is getting duplicated

I'm facing a behavior where a code that is running in a background bash subprocess (between parentesis and &) is being sometimes, apparently, called twice:

That's the case:

# script start.sh
#!/bin/bash

echo "Starting ..."

(
  java -server ...

  ret=$?
  log "Process has stopped returning: [$ret]"
  exit $ret
) &

In a normal scenario, running the start.sh script, two process would be created, one for the start.sh itself and other for the background bash subprocess (java program):

#> ps -ef | grep ^user
user 24538     1  0 Oct22 ?        00:00:00 /bin/bash start.sh
user 24539 24538  2 Oct22 ?        06:20:56 java -server ...

But, after a few days a new java process, that is child of 24539 process (java), is being created:

#> ps -ef | grep ^user
user 24538     1  0 Oct22 ?        00:00:00 /bin/bash start.sh
user 24539 24538 18 Oct22 ?        06:20:56 java -server ...
user 25888 24539  2 Oct25 ?        00:00:00 java -server ...

Does anyone have any idea why/how it's happening?

Upvotes: 1

Views: 75

Answers (1)

chepner
chepner

Reputation: 531325

This has nothing to do with the shell; if bash were involved, the parent process id of the new Java process would be 24538, not 24539. The Java process is forking itself. You'd have to look at the code to see why.

Upvotes: 2

Related Questions