• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 217
  • Last Modified:

Program that handle multiple request

Hi, I wish to write a program that can handle multiple request.

The idea is like this:
There is a controller that starts up 3 server processes to handle the incoming requests(using socket), and will start new process when any of the 3 server processes exits to ensure that there are always 3 server processes running.

How to do this? Is there any example online?
0
william007
Asked:
william007
  • 2
  • 2
2 Solutions
 
momi_sabagCommented:
hi
why do you want to start new process each time ? why not keep the same 3 servers online all the time
which platform are you using ?
0
 
william007Author Commented:
>why do you want to start new process each time? why not keep the same 3 servers online all the time
In case one of the server process is exit unexpectedly.

>which platform are you using ?
Linux FC 5
0
 
momi_sabagCommented:
ok
so your question basically is how do you sample the 3 servers in order to see that they are up ?
there is a system call - wait
you use the wait system call and wait on all the child process pid's,
you also use a timeout so you can check for new requests
when a child process will end, you will get notified from the wait function and you could fork off another child process
0
 
MysidiaCommented:
That's right, under Linux wait is want you want.

Actually, the specific system call is  waitpid()
You need

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

And the prototype of this function is
   pid_t waitpid(pid_t pid, int* statusCode,  int options);

pid is the pid number (from fork(), for instance)

Return value will be the PID or -1 if there's an error, or no process stopped.

The result will be written to statuscode, if waitpid is successful...
  WIFEXITED(*statusCode)   will tell you if the process has exited normally or with exit().
  WIFSIGNALED(*statusCode)  will tell you if the process exited due to an untrapped signal.

'options' passed to waitpid will be 0 or the constant 'WNOHANG', to make the call non-blocking.


0
 
william007Author Commented:
Thanks=)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now