Sample Header Ad - 728x90

when to use NOHUP

5 votes
2 answers
2918 views
I would like to know the purpose of nohup *these days*. I ask because I read this > Nohup is short for “No Hangups.” It’s not a command that you run by itself. Nohup is a supplemental command that tells the Linux system not to stop another command once it has started. That means it’ll keep running until it’s done, even if the user that started it logs out. The syntax for nohup is simple and looks something like this: > > nohup sh your-script.sh & > > Notice the “&” at the end of the command. That moves the command to the background, freeing up the terminal that you’re working in. > > Nohup works with just about any command that you run in the terminal. It can be run with custom scripts as well as standard system commands and command line utilities. With using linux distributions such as SLES 11.4, or RHEL/CentOS 7.x, I can - remote log in to linux over the network via SSH - run the simple program below, or any other, doing ./a.out & - log out of linux; type exit in the putty SSH terminal - my sample program below, or any other including bash, csh, or tcsh shell scripts, run to completion just fine without the need for nohup - typing exit in putty to close an SSH session, I would think that qualifies as a logout? Is there any purpose or value with nouhup today? Is it a kernel >= 3.x thing? For however long I can remember (kernel >= 2.6) I've never used nohup and have always just use & with no problems. Can someone give me a practical scenario where nohup would be used? #include #include /* sample C code, to print numbers to a file named zz.tmp the numbers 0 to 29 over 30 seconds */ int main ( int argc, char *argv[] ) { FILE *fp; int i; i = 0; fp = fopen("zz.tmp", "w" ); while ( i < 30 ) { fprintf( fp, "%d\n", i++ ); sleep( 1 ); } fclose( fp ); return 0; } **mysleep.sh** #!/bin/bash sleep 1000 On Centos 7.7, optiplex pc login with keyboard & mouse, my account is bash. I do nohup ./mysleep.sh and then **control-z**. When typing jobs I see + Stopped nohup ./mysleep.sh A ps -ef | grep mysleep shows that process id existing, but if I close the terminal window via X in upper right corner, that process goes away so it seems nohup is not working?
Asked by ron (8647 rep)
Feb 18, 2020, 02:37 PM
Last activity: May 21, 2025, 01:38 PM