you know... i could never figure out how to use forks in c++... my teachers can't explain it (yeah... i know... they must be great teachers, right?), i can't find a chewable explanation of how to use them... so... since, i guess students are better teachers than teachers themselves, specially because we know what it's like to not know (lol)... can anyone explain me or point me towards a nice explanation?

Nichito,

The use of fork() is shown quite clearly here:
http://docs.linux.cz/programming/c/unix_examples/fork.html

If you have no idea what fork does, I'll try to explain, but I'm VERY rusty on how to use them.

Your program calls fork(). A new instance of your program is created, which will run concurrently with the original program. The program can work out if it is the original program (parent process) or the fork()ed program (child process) by checking the return value of fork(). Check the above link and you'll see this.

-Doug

i know how forks work... what i don-t know is how to use them...

Well.... do you have any reason you need to fork off a process in the first place?

not now... but not a long time ago i needed to, so i would like to learn before i run into that situation again...

well... actually, that fork was the reason i joined daniweb... i was so mad i couldn't figure it out, i needed to ask for help... and in the end i didn't use it because i didn't understand it...

Well I am no expert on forks either, but I have done a little with them in C (I assume principals will be the same with C++). So with a fork you spawn many process from a "parent". And so its use it with using multiple threads. An example of this would be a web server that is run as a process, and as connections are requested, this main process will spawn a "child" (using fork) to manage the particular connection (thus allowing multiple simultaneous connections). As I said, I am no expert so if I have made errors somebody correct me. Also remember to reap each child process, otherwise you can see yourself creating a "fork bomb" and consequently quickly using up your system resources (I am an expert at doing this :)). Hope I was some help

Well I am no expert on forks either, but I have done a little with them in C (I assume principals will be the same with C++).

actually... AFAIK, they follow the same principles, but don't look alike...

i know the work by using a parent and children... but what i don't know is HOW to do it... what commands to use and that stuff...

Sorry, I obviously misunderstood what you wanted. I could post some C examples, but considering this is the C++ forum and you said they look different, I'll only do it if you request it. Hopefully others are a bit more cluey about C++ forks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.