Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Oct 10th, 2004, 6:59 PM   #1
Tazz13
Newbie
 
Join Date: Oct 2004
Posts: 3
Rep Power: 0 Tazz13 is on a distinguished road
Hi,

I need some help with using the fork() command. What I need to do is have the program create 3 child processes using fork() then each of the 3 child processes create 1 process each using fork(). Then I need the proces ID's of each process to be printed.

I have gotten the first part where I create 3 child processes, now I don't know where to insert another fork() such that each of the 3 child processes creates 1 child process of its own.

I am using the bash shell and using the "Pico" text editor to write this C Program. I am using the 'gcc' compile command to compile the program.

Here is the code I have so far:

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>

void main()
{
 *int i;
 *int n;
 *pid_t childpid;

 *for(i = 1; i < 4; ++i)
 *{
 * * if((childpid = fork()) <= 0)
 * * {
 * * * *break;
 * * }
 *}

 *fprintf(stderr, "This process %ld with parent %ld\n", (long)getpid(), (long)getppid());
}
Tazz13 is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:51 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC