Solved

Program that handle multiple request

Posted on 2006-10-29
5
182 Views
Last Modified: 2010-04-15
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
Comment
Question by:william007
  • 2
  • 2
5 Comments
 
LVL 37

Expert Comment

by:momi_sabag
ID: 17828914
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
 
LVL 9

Author Comment

by:william007
ID: 17828924
>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
 
LVL 37

Accepted Solution

by:
momi_sabag earned 300 total points
ID: 17828980
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
 
LVL 23

Assisted Solution

by:Mysidia
Mysidia earned 200 total points
ID: 17829929
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
 
LVL 9

Author Comment

by:william007
ID: 17853556
Thanks=)
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now