Solved

Program that handle multiple request

Posted on 2006-10-29
5
209 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

695 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