473,511 Members | 15,178 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

switch + fork

18 New Member
ok a have the next code:
Expand|Select|Wrap|Line Numbers
  1.       /* we use a fork to create a child process that sniffs the answers */
  2.       switch(pid = fork())
  3.     {
  4.     case -1: 
  5.       pe("Error fork");
  6.       exit(1);
  7.     case 0:
  8.       sniffer(filter,nbr_pkt, 0, dev, resolve);
  9.       exit(1);
  10.       break;
  11.     default:
  12.       /* we wait to let the sniffer starts */
  13.       sleep(1);
  14.       /* we send our packets */
  15.       while (nbr_pkt > 0) {
  16.         if (ack_flag == 1)    
  17.           send_tcp(srcaddr_r, htons(srcport), dstaddr_r, htons(dstport), th_seq, th_ack,  0, ttl, htons(ipid));
  18.         if (syn_flag == 1) {
  19.           th_ack = 0;
  20.           send_tcp(srcaddr_r, htons(srcport), dstaddr_r, htons(dstport), th_seq, th_ack,  1, ttl, htons(ipid));
  21.         }
  22.         --nbr_pkt;    
  23.       }
  24.       /* we start a timer :after 3 seconds, a signal SIGALRM is emitted */
  25.       alarm(3);
  26.       /* we wait for any signal (SIGALRM from hprobe or SIGCHLD from the sniffer) */
  27.       pause();
  28.     }
  29.       exit(0);
  30.     }
what i am interested to knew is what is happened when the exit(1) executes in the child process, why the sniffer isn't stoping and it keeps running, from what i knew the exit() function shall exit from the program, but in this case it is something else, and i don't understand how that is done.
thx. and if you have any questions regarding any another aspect of the program that will help you explain me this statement i will gladly answer
Jun 14 '07 #1
2 4667
Silent1Mezzo
208 New Member
Could you please put your code in [code] brackets to make it more readable...Thanks
Jun 14 '07 #2
ogedezvoltare
18 New Member
ok a have the next code:
Expand|Select|Wrap|Line Numbers
  1.       /* we use a fork to create a child process that sniffs the answers */
  2.       switch(pid = fork())
  3.     {
  4.     case -1: 
  5.       pe("Error fork");
  6.       exit(1);
  7.     case 0:
  8.       sniffer(filter,nbr_pkt, 0, dev, resolve);
  9.       exit(1);
  10.       break;
  11.     default:
  12.       /* we wait to let the sniffer starts */
  13.       sleep(1);
  14.       /* we send our packets */
  15.       while (nbr_pkt > 0) {
  16.         if (ack_flag == 1)    
  17.           send_tcp(srcaddr_r, htons(srcport), dstaddr_r, htons(dstport), th_seq, th_ack,  0, ttl, htons(ipid));
  18.         if (syn_flag == 1) {
  19.           th_ack = 0;
  20.           send_tcp(srcaddr_r, htons(srcport), dstaddr_r, htons(dstport), th_seq, th_ack,  1, ttl, htons(ipid));
  21.         }
  22.         --nbr_pkt;    
  23.       }
  24.       /* we start a timer :after 3 seconds, a signal SIGALRM is emitted */
  25.       alarm(3);
  26.       /* we wait for any signal (SIGALRM from hprobe or SIGCHLD from the sniffer) */
  27.       pause();
  28.     }
  29.       exit(0);
  30.     }
what i am interested to knew is what is happened when the exit(1) executes in the child process, why the sniffer isn't stoping and it keeps running, from what i knew the exit() function shall exit from the program, but in this case it is something else, and i don't understand how that is done.
thx. and if you have any questions regarding any another aspect of the program that will help you explain me this statement i will gladly answer
I understand now for what is the exit(1) function call, it will generate an SIGCHLD signal that will be caught later in the program with the signal() function.
Now i what to know what is the break instruction roll, and it will ever be executed, if will look that the exit(1) function is just above it?
Jun 15 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
5885
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
27
5934
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
8252
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
1
5051
by: vduber6er | last post by:
Hi I want to have a wait page while the rest of the cgi does its process, but it seems like the wait page waits till everything is complete and never appears. I've tried forking twice already as...
3
2707
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
12206
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
5660
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...
9
5249
by: Gilles Ganault | last post by:
Hello I need to launch a Python script, and fork it so that the calling script can resume with the next step will the Python script keeps running. I tried those two, but they don't work, as...
2
4225
by: Radz | last post by:
when the fork system call is executed, a new process is created. The original process is called the parent process whereas the new process is called the child process. The new process consists of a...
0
7137
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7349
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,...
0
7417
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7074
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
3219
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...
0
3210
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1572
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 ...
1
780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
445
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.