1

I would like to start a background process from bash script, but at the same time give it another name and also make it immune to CTRL-C. I tried the following:

exec -a NiceName java -cp ....long java command line &
tail -f logs/the.log

I want the exec to provide the process another name than just java. I want to start it in the background to be able to immediately run tail on the logs of the process to verify the startup.

This works until I hit CTRL-C to stop the script/tail because the SIGINT is passed to the java process which terminates too.

I also tried combinations of (exec ...&) and (exec ...)&. What does work is

exec bash -c "java command line escaping hell&"
tail -f logs/the.log

but I would hope there is way without escaping hell. I also tried things with disown to no avail.

If I remove the exec, the sub-process is immune to CTRL-C, but then I cannot give it a name.

  • start it with at. – mikeserv Jan 3 '16 at 0:50
1

After some more experimenting I found the way to do this:

(trap "" SIGINT; exec -a NiceName java -cp ....long java command line &)
tail -f logs/the.log

Ignoring the SIGINT in the subshell is inherited by the execed java command. The foreground running bash/tail can still be terminated with CTRL-C.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.