0

Can somone please explain to me what does fork() != 0 mean? From what I understand I think it means if fork is not false? Or if fork is true then.... I dont understand how Fork() can be true or false, seeing that it just creates a copy of a process into a parent and child.

1 #include "csapp.h"
2
3 int main()
4  {
5    int x = 3;
6
7    if (Fork() != 0)
8        printf("x=%d\n", ++x);
9
10   printf("x=%d\n", --x);
11   exit(0);
12  }

EDIT: Also if a program where to say "if (Fork() == 0)" what would that mean?

Edited by wschamps42

4
Contributors
3
Replies
8
Views
4 Years
Discussion Span
Last Post by np complete
0

The return value of fork() will explain your questions

RETURN VALUE
On success, the PID of the child process is returned in the parent, and 0
is returned in the child. On failure, -1 is returned in the parent, no
child process is created, and errno is set appropriately.

0

can anyone give me nice tutorial of this fork() ? I just know only one thing which gerard said. i want to ask where is child process which is created ? This process is parent one. and how can we deal with child one ? hoping for best answers . ;)

1

@ nitin1

Don't you google your query first ?

Anyways, I found a tutorial, which starts with the basics. See this.

Also wiki has a nice article on fork() and forking in *nix systems.

There aremany tutorials that I found googling. You can also go through them.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.