Find the answer to your Linux question:
Results 1 to 3 of 3
Hi all I am just gaining some understanding the fork system by the following simple program. #include<unistd.h> #include<stdio.h> int main() { pid_t pid; printf("Inside the Parent Process \n"); if((pid = ...
  1. #1
    Just Joined!
    Join Date
    Nov 2009
    Posts
    4

    [SOLVED] Standard I/O redirection in linux

    Hi all

    I am just gaining some understanding the fork system by the following simple program.
    #include<unistd.h>
    #include<stdio.h>
    int main()
    {
    pid_t pid;
    printf("Inside the Parent Process \n");
    if((pid = fork())<0 )
    printf("Oooops Error Occured in forking \n");
    else if (pid ==0)
    printf("Inside the child process and the process id is %d \n", getpid());
    else
    printf( "inside the parent process and the process id is %d \n",getpid());

    }/*end of main */

    when i run the program in terminal i get the expected output, but when i redirect the output to a file the file does not have the printf information of the child process.
    my question is does linux perform standard I/O redirection for only the parent process and not the child process? or am i missing something.

    can someone clarify!!
    thanks

  2. #2
    Just Joined!
    Join Date
    Nov 2009
    Posts
    4
    Quote Originally Posted by abhiram7 View Post
    Hi all

    I am just gaining some understanding the fork system by the following simple program.
    #include<unistd.h>
    #include<stdio.h>
    int main()
    {
    pid_t pid;
    printf("Inside the Parent Process \n");
    if((pid = fork())<0 )
    printf("Oooops Error Occured in forking \n");
    else if (pid ==0)
    printf("Inside the child process and the process id is %d \n", getpid());
    else
    printf( "inside the parent process and the process id is %d \n",getpid());

    }/*end of main */

    when i run the program in terminal i get the expected output, but when i redirect the output to a file the file does not have the printf information of the child process.
    my question is does linux perform standard I/O redirection for only the parent process and not the child process? or am i missing something.

    can someone clarify!!
    thanks
    Never Mind, I found out my blunder in the program.

  3. #3
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    Out of curiosity, what was your solution? I'm looking at it and can't would be interested.
    DISTRO=Arch
    Registered Linux User #388732

Posting Permissions

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