Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <string.h>
- pid_t newChildProcess(){
- pid_t child_pid = fork(); //create childProcess
- if(child_pid==0){
- /*Child Process*/
- printf("Child Process\n");
- close(mypipefd[1]);
- read(mypipefd[0],buf1,sizeof(buf1));
- b = buf1;
- b++;
- execl(argv[0],argv[0],b,NULL);
- }else{
- /*Parent Process*/
- close(mypipefd[0]); // close useless stdin stream
- write(mypipefd[1], hex_num_a,sizeof(hex_num_a)); //stream to child
- (void)wait(&status); // wait for child
- printf("Parent Process\n");
- }
- }
- int main(int argc, char *argv[]) {
- pid_t child_pid1;
- pid_t child_pid2;
- int mypipefd[2];
- int ret;
- char buf[20];
- int status;
- char *b = argv[1];//argv[1]
- char *hex_num_a = argv[1];
- char *hex_num_b = argv[2];
- char buf1[4];
- memset(buf1,0,sizeof(buf1));
- ret = pipe(mypipefd);
- if(ret== -1){
- perror("pipe");
- exit(1);
- }
- if(b[0] !='1'){
- exit(EXIT_FAILURE);
- }
- child_pid11 = fork();
- if(child_pid1==0){
- /*Child Process*/
- if(child 1){
- printf("Child Process\n");
- close(mypipefd[1]);
- read(mypipefd[0],buf1,sizeof(buf1));
- printf("danach %s\n", buf1);
- //fprintf(stdout, "danach %s\n", buf1);
- b = buf1;
- b++;
- fprintf(stderr,"hallo %s\n",b);
- }else if(child 2){
- }
- execl(argv[0],argv[0],b,NULL);
- }else{
- /*Parent Process*/
- /*create 4 child processes*/
- newChildProcess();
- newChildProcess();
- newChildProcess();
- /* ------------- */
- close(mypipefd[0]);
- child_pid2 = fork();
- fprintf(stderr, "davor %s\n", hex_num_a);
- write(mypipefd[1], hex_num_a,sizeof(hex_num_a));
- (void)wait(&status);
- printf("Parent Process\n");
- }
- /* code */
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement