Solved

Program that handle multiple request

Posted on 2006-10-29
5
191 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

Suggested Solutions

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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

816 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

12 Experts available now in Live!

Get 1:1 Help Now