Click to See Complete Forum and Search --> : Question about Unix programming


wilbasket23
09-24-2002, 12:00 PM
hey guys got some question about Unix programming. what is fork()? what does it use for? what is wait()? what is it used for? what is pipe()? what does it use for? can u give me some information coz, i have to write a simuation program which simulate a call center which a customer call in we direct the call to the call center

bryce777
09-24-2002, 05:54 PM
fork() creates a new process, and pipe is used for interprocess communication.

So you can have code like

if(fork())
{
//do child process stuff here

return;
}

//do parent process stuff here

to spawn processes.

for pipe it is a little trickier and I can't remember how to do it exactly without looking it up, but it allows processes to communicate with each other or signal each other - usually to let them know when one finishes or to signal to the other one it has data waiting etc. I kind of like shared memory better, but people seem to have massive problems with it.

I do not think that wait() actually works like you would expect.

Last time I was doing unix programming, there was no wait or sleep functions that actually did what you expect, though this may have changed since then.

e_dawg
09-24-2002, 08:19 PM
I know what they do in Java, but it's been a while since I have done process forking in C++... I'd imagine wait() should work the same way, but who knows.

bryce777 basically explained it. I'm guessing you need handler processes that are forked off the main process to handle incoming connections, such as that in a socket handler class.