0

When a program/process is started in bash WITHOUT nohup, is it later possible(do something further) to let this program run even after the shell/terminal is closed.
Here is a great discussion on Difference between nohup, disown and & if any one is interested in refering.

In this question i want to share my observation about when a program is started without nohup.

Edit - Please ignore the orginal Q. Yes after disowning the process, killing the terminal/shell does not seem to matter. The process seems to run. With ps -ef | grep java I am able to see the process running even after the original terminal is closed.

2 Answers 2

2

With the limitations you describe above, there is not likely to be a way to keep the process running after the terminal has closed. Why? Despite the disown process, the shell inside the terminal remains the parent process of the java -jar myapp.jar process. While disown tells the shell process not to send HUP signals to java, when you close the terminal the bash process is killed first with the shell's parent process then inheriting the java process. That new parent will then send a HUP tp java, attempting to clean up all of it's inherited processes, and it is only the use of nohup in advance that prevents the java process from receiving and acting on that HUP signal.

2
  • well, i will try to add the ps output before and after disown. Give me few mins, am caught with something else at this moment. ++1
    – samshers
    Dec 27, 2021 at 15:57
  • seems i missed it. I used ps ef | grep java which seems to be incorrect in this case. With ps -ef | grep java i am able to view the java process. Quite silly. If you are fine to delete the A. I will be glad to delete the Q. your take.
    – samshers
    Dec 27, 2021 at 16:07
0

I assume the reason you are asking is that you've started command directly and want to keep it running after you log out and moreover you still want to be able to control it.

There are couple of things that controls the process lifetime. Two most important aspects are parent process (or process group) and control terminal.

If you run any interactive command you can easily send it to background (stop "ctrl+z" and continue in background "bg").

Now the tricky part - attaching the process to a different process group (and terminal). For terminal I usually use "screen" and for reattaching terminal - https://github.com/nelhage/reptyr

Of course there are alternatives to this tool. It is also important that not all the processes will behave correctly after this operation so your mileage may vary.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .