The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers > Homework & Coursework Questions
.
google unix.com



Homework & Coursework Questions Students must use and complete the template provided. If you don't, your post may be deleted! Special homework rules apply here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
nawk code explanation aoussenko Shell Programming and Scripting 3 06-04-2009 09:29 AM
BASH complete-filename & menu-complete together Mithu UNIX for Dummies Questions & Answers 0 01-06-2009 03:00 PM
AWK deifnition and some small code explanation amatuer_lee_3 Shell Programming and Scripting 0 05-17-2008 09:57 PM
need explanation Mari.kb UNIX and Linux Applications 1 11-23-2007 10:41 AM
Need explanation for the syntax(code) chandhar Shell Programming and Scripting 1 03-21-2007 04:59 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 4 Weeks Ago
prakashabii prakashabii is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 1
Post Please help with the following fork code..with complete explanation

I have the following piece of codes. Please explain it to me in great detail how are these codes working.

1. #include <stdio.h>
int main(){
int x;
x=0;
while (x<2 && fork()){
if (!fork()) execlp("echo","x++","x",0);
x++;
system("echo x+x");
}
}

2.

#include <stdio.h>
int i;
int main() {
for(i=0;i<2;i++){
if(fork())
fork();
}
printf ("%d\n", i);
system(("echo i++");
}


The attempts at a solution (include all code and scripts):[/B]
Output of 1:
x
x+x
x+x
x


Output of 2:
2
i++
2
i++
2
i++
2
i++
2
i++
2
i++
2
i++
2
2
i++
i++




Politechnico di Torino

Last edited by prakashabii; 4 Weeks Ago at 05:51 PM..
  #2 (permalink)  
Old 4 Weeks Ago
DukeNuke2's Avatar
DukeNuke2 DukeNuke2 is offline Forum Staff  
Soulman
  
 

Join Date: Jul 2006
Location: Germany, Berlin
Posts: 2,947
Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.
Sponsored Links
Closed Thread

Bookmarks

Tags
code, exec, fork

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:18 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0