re: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: Kasper Dupont: "Re: creating child processes"
- In reply to: Clunixchit: "creating child processes"
- Next in thread: Kasper Dupont: "Re: creating child processes"
- Reply: Kasper Dupont: "Re: creating child processes"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 27 May 2005 09:04:14 +0000 (UTC)
Thanks about those tips!!
i made some modifications, but my output is not what i wanted
i need to make 2 childs from the same parent.
i sld i make 2 switch for that?
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <fcntl.h>
//using GNU C exit status
#include <stdlib.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<5;i++){
write(desc,&A,sizeof(char));
}
// flushing stdio buffers
_exit(EXIT_SUCCESS;
case -1 : perror("fork");
exit(EXIT_FAILURE);
default : waitpid(one,NULL,0);
two = fork();
if ( two == 0 ) {
write(desc,&B,sizeof(char));
exit(EXIT_SUCCESS);
}
waitpid(two,NULL,0);
close(desc);
system("cat aba.txt");
exit(EXIT_SUCCESS);
}
}
- Next message: Kasper Dupont: "Re: creating child processes"
- Previous message: Kasper Dupont: "Re: creating child processes"
- In reply to: Clunixchit: "creating child processes"
- Next in thread: Kasper Dupont: "Re: creating child processes"
- Reply: Kasper Dupont: "Re: creating child processes"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|