473,385 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

fork inside an for

for(i=1;i<CONFIG_POLLER_FORKS;i++)
{
if((pid = fork()) == 0)
{
server_num=i;
break;
}
else
{
pids[i-1]=pid;
}
}

in this code:
the fork occurs just inside this little cut of code, I don't understand
if,
- in first fork(),
is create a child and it entries in if,
server_num receive a number 1
in break; i don't understand if, both child and parent break, or
just parent, and this child, continue or
execute de for() white parent?

excuse-me my inglish, I'm brazilian

Aug 8 '06 #1
5 1919
In article <11********************@i3g2000cwc.googlegroups.co m>,
mutley <mu***********@gmail.comwrote:
>for(i=1;i<CONFIG_POLLER_FORKS;i++)
{
if((pid = fork()) == 0)
Allow me to be the first (of many) to say:

Not portable. Can't discuss it here. Blah, blah, blah.

Aug 8 '06 #2
"mutley" <mu***********@gmail.comwrites:
for(i=1;i<CONFIG_POLLER_FORKS;i++)
{
if((pid = fork()) == 0)
{
server_num=i;
break;
}
else
{
pids[i-1]=pid;
}
}

in this code:
the fork occurs just inside this little cut of code, I don't understand
if,
- in first fork(),
is create a child and it entries in if,
server_num receive a number 1
in break; i don't understand if, both child and parent break, or
just parent, and this child, continue or
execute de for() white parent?

Its offtopic here, but ...

fork creates a NEW process. The break in the child code breaks to outside
the for loop : in a different address space. So effectively fork returns
twice - once in the child process and once in the parent process (the
else statement). The break cant break the parent because in the parent
fork return 0 - so the else statement is reached.

There are lots of tutorials available : use google.

http://yolinux.com/TUTORIALS/ForkExecProcesses.html
Aug 8 '06 #3

Troll Alert: Kenny McCormack

The only way to deal with trolls is to limit your reaction to reminding
others not to respond to trolls.

Information on trolls: http://members.aol.com/intwg/trolls.htm

--

Frederick Gotham
Aug 8 '06 #4
Richard <rg****@gmail.comwrites:
"mutley" <mu***********@gmail.comwrites:
>for(i=1;i<CONFIG_POLLER_FORKS;i++)
{
if((pid = fork()) == 0)
{
server_num=i;
break;
}
else
{
pids[i-1]=pid;
}
}
[snip]
Its offtopic here, but ...
[snip]

.... it's on topic on comp.unix.programmer.

(Please don't try to answer off-topic questions, especially when
there's a group where it's topical, full of experts who probably know
more about this than either of us.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 8 '06 #5
Frederick Gotham <fg*******@SPAM.comwrites:
Troll Alert: Kenny McCormack

The only way to deal with trolls is to limit your reaction to reminding
others not to respond to trolls.

Information on trolls: http://members.aol.com/intwg/trolls.htm
Frederick, at this point I think almost everyone is aware that KM is a
troll, and most of us have been doing a good job of ignoring him. By
posting this followup every time he posts, you're giving him more
attention.

My suggestion: Ignore him completely. If anyone else posts a
followup, post a gentle reminder not to feed the troll (unless someone
else has already done so).

You might also consider killfiling him, but that's entirely up to you.

Your efforts are appreciated, but I don't believe they're necessary.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 8 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Benoit Dejean | last post by:
hello, i have a question about forking processes atm, i have some code which i want to rewrite os.system("cd ~ && exec " + cmd + " & disown") i want to remove this os.system call
6
by: shellcode | last post by:
the code: ------fork.c------ #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> int main() {
27
by: steve | last post by:
I was given the following code, and asked what the possible outputs could be. We're learning about processes and forking. int value; int main(){ int pid, number = 1; value = 2; pid = fork();...
11
by: ramu | last post by:
Hi All, We know that a c function never returns more than one value. Then how come the fork() function returns two values? How it is implemented? Regards
3
by: thrillseekersforever | last post by:
The questions(A&B) are to fine no# of process running from the below codes. However, I couldn't decipher the solution. Will someone please throw some light on this? Thanks a lot!! A] void...
5
by: JoeW | last post by:
Now before I go into detail I just want to say that this is purely for my own benefit and has no real world usage. I remember way back when the tool for *nix systems called forkbomb was created. I...
3
by: CMorgan | last post by:
Hi everybody, I am experiencing an annoying problem with fork() and execv(). In my program I need to launch the "pppd" from a thread, so, I create a new process with fork and then in the child...
1
by: 3srt | last post by:
Hello, I created a simple 'server' script that will accept input from a cgi script. The server will handle multiple connections on the same port, also. In a nut shell, this 'server' script will...
0
by: lilly07 | last post by:
I tried a small example in perl forking. I opena connection with sql database in the parent or main program as follws: $dbh = DBI->connect("DBI:mysql:database=$database;host=$host", $user,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.