Spawn background processes on *nix that Ctrl-C doesn't kill

70 views
Skip to first unread message

Brad Wood

unread,
Mar 30, 2018, 1:20:24 AM3/30/18
to jline...@googlegroups.com
I think this is more of a *nix question but I wanted to ask here since it's related to the JLine signal handlers and likely something that's been run into before.  This came up a few days back in another thread and I asked about it but the question looks to have gotten lost in the other conversation so I'm breaking it out as its own thread.

My console app starts up background servers with ProcessBuilder on a user's PC.   The process builder is not held open.  I actually fire off an intermediate process which actually spins up the server and then exits.  Nonetheless, even though the original Java CLI process that JLIne is running in no longer has any direct ties to this background server, it was mentioned that the operating system still groups those processes together.  

The regression, which did not happen in Jline2, is that hitting Ctrl-C in the shell will kill off any background servers the user had started, even if they were started hours before.  I'm catching the thread interrupt in my code and handling it (by cancelling the currently-executing command, or if the user is setting at the shell, doing nothing and telling them to use Ctrl-D to exit the shell). Point is, the Ctrl-C is not killing the Jline process, but all previously spawned external processes do get killed off which I don't want.

Looking around on the interwebs, I'm seeing references to using nohup 

So just want to confirm, is this the only way out for me?  Am I missing some sort of configuration that would affect this behavior?

Thanks!

~Brad

Developer Advocate
Ortus Solutions, Corp 

ColdBox Platform: http://www.coldbox.org 

Guillaume Nodet

unread,
Mar 30, 2018, 2:35:36 AM3/30/18
to jline...@googlegroups.com
No, you're not missing anything.  You do need to create a child detached from the group and the script on that thread seems the way to go.

--
You received this message because you are subscribed to the Google Groups "jline-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jline-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brad Wood

unread,
Mar 30, 2018, 10:12:59 AM3/30/18
to jline...@googlegroups.com
Thank you for the confirmation.  I'll move forward with a nohup implementation when running on *nix. 

Thanks!

~Brad

Developer Advocate
Ortus Solutions, Corp 

ColdBox Platform: http://www.coldbox.org 


Brad Wood

unread,
Apr 3, 2018, 7:50:23 PM4/3/18
to jline-users
Just to close the loop on this one-- this was a total pain to get working.  Mostly because everyone assumes you want to background any process that you don't want to be in the same *nix thread group.  So every ready-made answer I found on StackOverflow involving nohup or disown all missed the mark one way or another since I actually was interested in capturing the standard out of the process while it was running.  I ended up using nohup to spawn my external servers and redirecting the process output to a text file which I could tail to capture.  Here is the shell script my app is now using to start these external processes on *nix machines such that I can still see the console output of the process, but it is run in a separate thread group which makes it impervious to interrupt signals fired by Ctrl-C.


Hopefully that will inspire someone who finds themselves in a similar boat.

Thanks!

~Brad
Reply all
Reply to author
Forward
0 new messages