1824169 Members
3295 Online
109669 Solutions
New Discussion юеВ

Nohup question

 
SOLVED
Go to solution
Carlo Henrico_1
Regular Advisor

Nohup question

I am probably just doing something stupid, but if I submit a job as follows:

nohup jobname parameter_file &

and I exit, it says there are running jobs. If I then exit again it terminates the jobs. What should I do to submit a job allowing me to exit my session without the job terminating?

Thanks

Carlo
Live fast, die young - enjoy a good looking corpse!
11 REPLIES 11
Thierry Poels_1
Honored Contributor

Re: Nohup question

Hi,
your shell warns you that you have running jobs. But when you exit your nohup jobs should keep on running. No special configuring required.
Put a sleep command in your script, and "ps -ef | grep sleep" after exiting should show you job.
good luck,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Vincent Stedema
Esteemed Contributor

Re: Nohup question

Are you 100% sure that the job terminates when you exit? As far as I can see, you're not doing anything wrong.

Vincent

Carlo Henrico_1
Regular Advisor

Re: Nohup question

I have just re-tested it (there are two jobs) and they definately do terminate. They are both C++ programs developed in-house. Maybe there is something special which should be included in the code?

Carlo
Live fast, die young - enjoy a good looking corpse!
Carlo Henrico_1
Regular Advisor

Re: Nohup question

...maybe I should pose this question under the "Languages" forum?

Carlo
Live fast, die young - enjoy a good looking corpse!
Vincenzo Restuccia
Honored Contributor

Re: Nohup question

Verify the priority of the job with ps -elf|grep job,and list it with nice (see man nice).
Carlo Henrico_1
Regular Advisor

Re: Nohup question

Vincenzo

Any idea what I should do with its nice value once I know it?

Carlo
Live fast, die young - enjoy a good looking corpse!
Thierry Poels_1
Honored Contributor
Solution

Re: Nohup question

Hi,
I've never started a C-prog through nohup directly. I've always used a surrounding shell script.
Maybe, just maybe, a C-prog stops if it's detached from it's parent shell; just a (very very) wild guess.
Try putting a sleep command in a shell script, start it through nohup, logoff, and check if that keeps running. If so, put your prog in a shell script.
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Laurent Paumier
Trusted Contributor

Re: Nohup question

Watch the file nohup.out for error messages.

You may also try redirecting stdin :
nohup your_prog
Stefan Schulz
Honored Contributor

Re: Nohup question

I had a problem with a programm which checked if the parent process was still running. This programm also died if i loged out, even when using nohup.

Luckily this programm had an option to disable this check for the parent process.

But i think all you have to do is to make sure that there is a process alive when you logout.

So i would suggest you write a small wraperscript which calls your programm and nothing more. Then you start this script with nohup. Then your script doesn't die and you programm should find its parent process still running.

Hope this helps. Stefan
No Mouse found. System halted. Press Mousebutton to continue.
W.L. Alsemgeest
Occasional Advisor

Re: Nohup question

In a other nohup question I remember the following solution:
Make a script that first do a sleep for, lets say 100 sec, and then perform your job.
sometimes the nohup is not working correct and the sleep is is forsing the job to run correctly with "nohup".
After starting the script, close your terminal. The job is now running as a nohup job and after the sleep your program will run correctly.

Try it.
aku76
New Member

Re: Nohup question

So here's my script:

 

doit:

 

#!/usr/bin/ksh

 

 

sleep 10  # had to add this to get nohup to work

 

cat fie | myperlscript > file.out

 

exit

# end of script

 

I do

$ nohup doit &

 

$ exit

 

if I don't put the sleep in, it warns that I have running jobs, I have to type exit again, and nohup kills my process.

 

myperscript just reads stdin and prints it to stdout adding line breaks every 80 chars after the nearest '>'with no line break.

 

The file (xml) is so huge ( and all one line ) that I can't use sed to do this because it runs out of memory hence the perl script.  I am doing nohup, so I can go to bed and get the result in the morning.