Friday, May 3, 2024
 Popular · Latest · Hot · Upcoming
6
rated 0 times [  6] [ 0]  / answers: 1 / hits: 27033  / 2 Years ago, thu, february 17, 2022, 4:54:26

I've got an init.d script which I want it to work in the background, even when I quit from the terminal. However I've tried making it run in the background with nohup but had "no hope", because when I quit, by looking at the pstree I can see the PID disappears and thus nohup stops working.


Q: Is there another apart from nohup way of pushing a script that works in the foreground to the background, even after you quit the terminal?


More From » nohup

 Answers
2

Ok, so there are several options:




  • disown



You can combine disown and & to push your script to the background

$ disown [your_script] &
[your_script] can be checked by the jobs command. Once typed you will see:



$ jobs
[1]+ Running [your_script]



And the killing can be done by kill %1, the 1 refers to the job number seen above.
This is the better alternative to nohup as it does not leave the nohup.out files littered all over the file system.




  • screen



Is a "virtual" terminal which you can run from a "real" terminal (actually all terminals today are "virtual" but that is another topic for another day). Screen will keep running even if your ssh session gets disconnected. Any process which you start in a screen session will keep running with that screen session. When you reconnect to the server you can reconnect to the screen session and everything will be as if nothing happened, other than the time which passed.



Excellent source: Speaking UNIX: Stayin' alive with Screen".


[#20794] Saturday, February 19, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bearous

Total Points: 226
Total Questions: 116
Total Answers: 136

Location: Guernsey
Member since Sun, Jan 10, 2021
3 Years ago
;