Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

More simple UNIX questions...

Status
Not open for further replies.

qednick

Programmer
Jul 26, 2002
516
US
Hi again all,

I have three or four very small programs running on my linux web server - I executed them like this:

[tt]./app_name.out&[/tt]

My query is, occassionally, the programs stop running for no apparent reason. They all stop at the same time so it can't be anything to do with the code (ie. memory faults or whatever) because they are completely separate programs. They are also very small and use little memory.

Sometimes they can run for several days without a hiccup, other times they'll run for less than an hour. It's not the web server crashing that's causing it either.

Does anybody have any idea what can be causing it and a possible cure??

Also, is there a better/safer way of executing my programs in the background than using the ampersand '&' after the program name?? Is there any way I can get the programs to automatically restart if they stop for some reason??

:)

Thanks in advance!
tellis.gif

[sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup]​
 
There are many possible answers to this question. A process group leader, like your shell for example, can send a signal to terminate it's child processes. A 'hangup' signal (generated by ctrl-C to a foreground process) for example, usually terminates a program. When you exit the shell/window you invoked the program from, it gets this signal. Some signals can be trapped and/or ignored, for example, you can say:

% nohup ./myprogram &

And when you log off, it will run anyway. You can do this in shell scripts and C/C++ programs very easily.

What you really need to do is find the exit status of these processes by launching them from a program and monitoring the status with a wait or waitpid call.

Otherwise, this sounds like a question for a web server support group, not a general unix C++ question.
 
Thanks milenko! I'll give the [tt]nohup[/tt] a try and see if it helps! :)
tellis.gif

[sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup]​
 
You may also have unrelated program running in the backgroud that sends a kill-9 (which will kill any running process you own). Technically all server programs should be added to the boot script (see the man pages for the location of the script file for your particular distribultion of *nix), and be run from the root account.
 
I've had programs terminate for no apparent reason and it wasn't a kill -9 being sent to it. The program ran for a week, created a 15Gb log file and we finally tracked down that it was leaking memory and the system ran out of swap so the OS probably killed it. However, things like that are quite difficult to prove. The only other way I've found of keeping a program alive is to ping it (just a ps -ef | egrep progname will do) every so often (once a minute?). If it doesn't respond, assume it is dead and restart it.
 
thanks guys, the nohup has certainly improved things. In fact, the only time the programs did hang up is when the whole web server crashed. I'm pretty sure it's not a memory leak - the programs are incredibly small and I'm sure I've caught everything in them.
However, I find the ideas of boot scripts and "pinging" the programs very interesting - I'll look into those!! :)

Nick
tellis.gif

[sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup]​
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top