why does not fork() return pid of parent to child and zero to parent nd how can you find pid of parent when in child?
have you already seen this ? http://www.unix.com/unix-dummies-questions-answers/12815-fork-function.html
no
and i really dont understand it -.-
it's a discussion about pid's after fork() use
sir um can u please answer my question?
according to this: http://beej.us/guide/bgipc/output/html/multipage/fork.html you should use this: So, I call fork() and save the return value in the pid variable. fork() is easy, since it can only return three things: 0 If it returns 0, you are the child process. You can get the parent's PID by calling getppid(). Of course, you can get your own PID by calling getpid(). -1: If it returns -1, something went wrong, and no child was created. Use perror() to see what happened. You've probably filled the process table—if you turn around you'll see your sysadmin coming at you with a fireaxe. else: Any other value returned by fork() means that you're the parent and the value returned is the PID of your child. This is the only way to get the PID of your child, since there is no getcpid() call (obviously due to the one-to-many relationship between parents and children.)
ok got it thanks getppid()
you're welcome
:D
Join our real-time social learning platform and learn together with your friends!