473,804 Members | 3,809 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

fork inside an for

for(i=1;i<CONFI G_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 1947
In article <11************ ********@i3g200 0cwc.googlegrou ps.com>,
mutley <mu***********@ gmail.comwrote:
>for(i=1;i<CONF IG_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<CONFI G_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.c omwrites:
"mutley" <mu***********@ gmail.comwrites :
>for(i=1;i<CONF IG_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.progr ammer.

(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_Keit h) 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_Keit h) 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
5913
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
2399
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
5993
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(); value = value + 2; number = number + 2;
11
8281
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
2723
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 main() { .... pid1 = fork(); if (pid1) pid2 = fork(); .....
5
12236
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 recently explained it to a friend of mine and at that time decided to see if I could replicate it in C#. I have created an application that, to me at least, mimics what fork would/should do on *nix/bsd systems. I know that fork spawns a new...
3
5688
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 process I launch with execv the pppd to connect an embedded system to internet. The problem is that pppd fails. I have made two test program just to discard bugs (my applications is really big) and the result is that when I call execv from a...
1
1651
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 take in variables, and fork off a process to sleep for a given amount of time, and then send the user an email (and perform other functions). Here is my problem: I receive a confirmation e-mail once the connection has been made, but i do not...
0
1737
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, $pass) || die "\nDB connection error!\n"; And I try to execute some mql commands and it works fine. As one of the process will take more time to finish, I open a fork as follows. And I try to do some sql commands inside the child process as below: ...
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10569
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10075
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9140
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7615
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4295
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.