LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   C++ and PIDs (http://www.linuxquestions.org/questions/programming-9/c-and-pids-205618/)

dbcoder 07-15-2004 08:52 PM

C++ and PIDs
 
I'm going to right a program (hopefully) for my friend who runs a NeverWinter Nights server that crashes every once and a while.

I was thinking I can have a program running that records the PID of the server when it runs, and if it's absent (it crashes) it starts it again.

I just need to know where to look for that sort of programming. I need to learn how to write code that interacts w/ the operating system.

Can anyone point out a site that would have tuts?

itsme86 07-15-2004 08:58 PM

It might be easier to just write a wrapper program:

Code:

while(1)
  if(WEXITSTATUS(system("command_to_start_server")) <= 0)
    break;

system() won't return until the server exits (or crashes) and if the server is sane it will return 0 on a successful exit. If it crashes the return value should be greater than 0.

Then you can just run this wrapper program to start the server and it should constantly restart it as long as it crashes and doesn't exit normally.


All times are GMT -5. The time now is 06:07 AM.