Solved

Program that handle multiple request

Posted on 2006-10-29
5
173 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
Comment Utility
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
Comment Utility
>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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks=)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
In desperate need of help 8 129
posix semaphore deadlock 13 108
Line meaning 9 75
Arduino EDI - Programming language 3 60
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
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 recursion in the C programming language.

772 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

10 Experts available now in Live!

Get 1:1 Help Now