how to creat 1 parent to call 3 children


 
Thread Tools Search this Thread
Top Forums Programming how to creat 1 parent to call 3 children
# 1  
Old 10-19-2005
Question how to creat 1 parent to call 3 children

hi there, im trying to produce this program that would run at first, and when it runs it will fork one child process to [exec] a program and then another forking to run this other program, and then another one .

i cant seem to get it right can someone help me please here is what is got so far:

Code:
int main ()
{
//page 265
pid_t fork_1, fork_2;

printf("before: my pid is %d\n", getpid());//who am i
printf("before: my ppid is %d\n", getppid());//who am i

	fork_1 = fork();
	fork_2 = fork();




	if (fork_1 == -1
	perror("fork not done");

	else if (fork_1 ==0) {
	printf("Hi Dady--==Process ID==-- %d\n",getpid());
	execl("/home/knoppix/assi/count.out","./count.out",NULL,NULL);
	printf("fork_1 is %d\n i died :( \n",fork_1);
	sleep(2);
	
}
	else if (fork_2 == 0) {
	fork();
	printf("hi its me dady --==Process ID==-- %d\n",getpid());
	execl("/home/knoppix/assi/count.out","./count.out",NULL,NULL);
	sleep(2);

}
	else
	wait(NULL);
	printf("Im The Parent ID is %d\n",getpid());		

	printf("pid %d Terminated...........\n",getpid());
}

# 2  
Old 10-21-2005
Code:
	fork_1 = fork();
	fork_2 = fork();

One hint: First fork() results in two processes. They both execute next statement... 4 processes now.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

One parent, multiple children pipe with fork()

The task I have to do is something along the lines "I receive some input and based on the first character I send it through pipe to one of the children to print". The scheme it is based on is 1->2; 1->3; 1->4; 2 will print all the input that starts with a letter, 3 will print all the input that... (2 Replies)
Discussion started by: Ildiko
2 Replies

2. Homework & Coursework Questions

program to send messages to parent using pipes and select system call

Write a program using select, which will create some number of child processes that continuously send text messages to the parent process using pipes. Each child has its own pipe that it uses to communicate with the parent. The parent uses select () to decide what pipes should be processed to... (1 Reply)
Discussion started by: ripssingh
1 Replies

3. Web Development

chrome window.parent call javascript func fail

Hi Everyone, Please refer to attached test.zip. Open a.htm, tested under IE, Safari, Firefox no problem, but ONLY google chrome fail, seems cannot use call parent javascript function under the child iframe. Please advice. Thanks (1 Reply)
Discussion started by: jimmy_y
1 Replies

4. Debian

creat image for the new kernel

Hello friends, I have compiled the kernel . But now i am facing the problem as to how we can create the initrd.img for the specific kernel. I was compiling the 2.6.29 kernel. to create initrd.img for 2.6.29 what i did is : cd /boot mkinitramfs-kpkg -o initrd.img-2.6.29 2.6.29... (2 Replies)
Discussion started by: pradeepreddy
2 Replies

5. Solaris

creat flash archive

I want take a flash backup by flar command for specific files like: / , /boot, /tmp I am trying this command but its not working # flar -n archive1 -f /,/boot,/tmp -F -c /home/arc1.flar Please can any body help me __.____._ (2 Replies)
Discussion started by: kmuqalled
2 Replies

6. UNIX for Advanced & Expert Users

Fork() 1 Parent 3 Children

Hi, as I understand fork(), it makes a copy of the parent which becomes a child. But is there anyway to make three children for that one parent. So in other words, if I look up the getppid() of the children, I want them to have the same value?? Thanks in advance to any help! (1 Reply)
Discussion started by: MS_CC
1 Replies

7. Shell Programming and Scripting

full path of a file situated either in parent's dir. or parent's parent dir. so on...

hi experts(novice people can stay away as it is no child's game), i am developing a script which works like recycle bin of windows. the problem i am facing is that when ever i am trying to delete a file which is situated in parent directory or parent's parent directory i am unable to... (1 Reply)
Discussion started by: yahoo!
1 Replies

8. AIX

Creat a File with a Specific Size

Hi everybody, Is there a command that can create a new file with a specific size? Thanks in advance. (3 Replies)
Discussion started by: aldowsary
3 Replies

9. Programming

Creat-Crontab

Dear All, Please any send the idea and designing for creating the crontab in c Thank in advanced (2 Replies)
Discussion started by: dhinesh
2 Replies
Login or Register to Ask a Question