creating child processes
From: Clunixchit (chitlesh_at_gmail-dot-com.no-spam.invalid)
Date: 05/27/05
- Next message: Kasper Dupont: "Re: creating child processes"
- Previous message: George: "Re: Error: Invalid Module format"
- Next in thread: Kasper Dupont: "Re: creating child processes"
- Reply: Kasper Dupont: "Re: creating child processes"
- Reply: Clunixchit: "re:creating child processes"
- Reply: Clunixchit: "Problem solved"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 27 May 2005 07:45:58 +0000 (UTC)
am I lame ??
sounds like i didnt grab something !!!
whats wrong??
y for 2 loops, it prints 3 loops?
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <fcntl.h>
int main(){
pid_t one, two;
char A = 'A';
char B = 'B';
int i=0;
int desc = open ("aba.txt", O_CREAT | O_RDWR , 0700
);
if ( desc < 0 ) {
perror ("open");
exit(-1);
}
lseek(desc,0,sizeof(char));
one = fork();
switch ( one ) {
case 0 : for(i=0;i<2;i++){
write(desc,&A,sizeof(char));
}
exit(0);
case -1 : perror("fork");
exit(-1);
default : waitpid(one,NULL,0);
two = fork();
if ( two == 0 ) {
write(desc,&B,sizeof(char));
waitpid(two,NULL,0);
}
close(desc);
system("cat aba.txt");
exit(0);
}
}
in the end i wish to output ABABABABAB
- Next message: Kasper Dupont: "Re: creating child processes"
- Previous message: George: "Re: Error: Invalid Module format"
- Next in thread: Kasper Dupont: "Re: creating child processes"
- Reply: Kasper Dupont: "Re: creating child processes"
- Reply: Clunixchit: "re:creating child processes"
- Reply: Clunixchit: "Problem solved"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|