Find the answer to your Linux question:
Results 1 to 3 of 3
Hi, i would like to pass a string from a father process to a child process,in which i use exec.I read that i can do that with pipes.How can i ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Dec 2012
    Posts
    2

    Using pipe in forked processes.


    Hi,

    i would like to pass a string from a father process to a child process,in which i use exec.I read that i can do that with pipes.How can i have access to the string in the programm ,which is loaded to the child process?

  2. #2
    Linux Newbie
    Join Date
    Nov 2012
    Posts
    232
    hi,

    what language ?

    show some code sample, input, desired output...

  3. #3
    Just Joined!
    Join Date
    Dec 2012
    Posts
    2
    In C

    This is programm A:

    int main(){
    char* msg;
    int fd[2];
    int pid, status, rpipe;

    while(1){
    msg = (char*)(malloc(COM_SIZE*sizeof(char)));

    rpipe = pipe(fd);
    if(rpipe==-1)
    printf("Pipe doesn't work\n");

    printf("Twitspeak is connected!Please write your twits!\n");

    fgets(str, COM_SIZE, stdin);

    pid=fork();

    if(pid<0){puts("pid<0 this is bad!");}
    if(pid>0){//parent
    printf("%s", msg);
    close(fd[0]);
    wait(&status);
    close(fd[1]);
    free(msg);

    }else if(pid == 0){//child
    close(fd[1]);
    execv("twitsay","twitsay",msg,null);
    }
    }
    }

    How can i have access to fd of this programm in programm twitsay,to get the string in twitsay programm?

  4. $spacer_open
    $spacer_close

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •