UNIX Programming and Technical

Q. Predict the output of the following program code

A.
main()
{
fork();
printf("Hello World!");
}
Answer:
Hello World!Hello World!
Explanation:
The fork creates a child that is a duplicate of the parent process. The child begins from the fork().All the statements after the call to fork() will be executed twice.(once by the parent process and other by child). The statement before fork() is executed only by the parent process.

Read Solution (Total 0)

UNIX Other Question

Q. Explain fork() system call.

A. The `fork()' used to create a new process from an existing process. The new process is called the child process, and the existing process is called the parent. We can tell which is which by checking the return value from `fork()'. The parent gets the child's pid returned to him, but the child gets 0 returned to him.
Q. How can you get/set an environment variable from a program?

A. Getting the value of an environment variable is done by using `getenv()'.
Setting the value of an environment variable is done by using `putenv()'.