Michael
Michael

Reputation: 2982

Get return code of disowned background process

My process is created using nohup and will be disowned to make it independent from killing of its parent process.

I need the return code of this backgroud process, which was disowned and nohuped:

nohup bash -c 'exit 123' "$@" >log.txt 2>&1 </dev/null &
pid=$!
disown $pid
tail --pid=$pid -f log.txt

Now the script will return 0. But it should return the exit code of my process started using nohup.

How to get the exit code of the process?

Upvotes: 0

Views: 265

Answers (1)

Michael
Michael

Reputation: 2982

OK, I found a solution by using setsid insteed of nohup and disown:

setsid bash -c 'exit 123' "$@" >log.txt 2>&1 </dev/null &
pid=$!
tail --pid=$pid -f log.txt
wait $pid

Now it returns the exit code of my background process and it still ignores killing of the parent process.

Upvotes: 2

Related Questions