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?

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.

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 . ;)

@ 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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.