Find the answer to your Linux question:
Results 1 to 2 of 2
hi, in case i fork a process and i want that process to return a value that should be printed in parent process....is that possible without sharing memory or without ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2005
    Location
    India
    Posts
    12

    can a child process return a value to a parent process ??


    hi,

    in case i fork a process and i want that process to return a value that should be printed in parent process....is that possible without sharing memory or without using vfork() ????

    is it possible to do it as we do it while using functions in C that return values ??

    thanks,
    jd

  2. #2
    Linux Newbie
    Join Date
    Oct 2004
    Posts
    158
    from the waitpid() man page
    Code:
      WIFEXITED(stat_val)      Evaluates to a non-zero value if status
                                        was returned for a child process that
                                        terminated normally.
    
      WEXITSTATUS(stat_val)    If the value of WIFEXITED(stat_val) is
                                        non-zero, this macro evaluates to the
                                        low-order 8 bits of the status argument
                                        that the child process passed to _exit()
                                        or exit(), or the value the child
                                        process returned from main().
    In other words, you can get the exit() status from the child process using waitpid().

    You need to read all of the man page because there are some other considerations.

Posting Permissions

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