Reputation: 2982
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 disown
ed and nohup
ed:
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
.
wait $pid
doesn't work and always returns 0.How to get the exit code of the process?
Upvotes: 0
Views: 265
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