Unix Questions and Answers

Predict the output of the following program code 

main()
{
fork(); fork(); fork();
printf("Hello World!");

Answer:

"Hello World" will be printed 8 times.
Explanation:
2^n times where n is the number of calls to fork() 
 

List the system calls used for process management:

System calls Description
- fork() To create a new process
- exec() To execute a new program in a process
- wait() To wait until a created process completes its execution
- exit() To exit from a process execution
- getpid() To get a process identifier of the current process
- getppid() To get parent process identifier
- nice() To bias the existing priority of a process
- brk() To increase/decrease the data segment size of a process.
 

How can you get/set an environment variable from a program?

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

How can a parent and child process communicate?

A parent and child can communicate through any of the normal inter-process communication schemes (pipes, sockets, message queues, shared memory), but also have some special ways to communicate that take advantage of their relationship  as a parent and child. One of the most obvious is that the parent can get the exit status of the child.
 

What is a zombie?

When a program forks and the child finishes before the parent, the kernel still keeps some of its information about the child in case the parent might need it - for example, the parent may need to check the child's exit status. To be able to get this information, the parent calls `wait()'; In the interval between the child terminating and the parent calling `wait()', the child is said to be a `zombie' (If you do `ps', the child will have a `Z' in its status field to indicate this.)
 

What are the process states in Unix? 

As a process executes it changes state according to its circumstances. Unix processes have the following states:
Running : The process is either running or it is ready to run .
Waiting : The process is waiting for an event or for a resource.
Stopped : The process has been stopped, usually by receiving a signal.
Zombie : The process is dead but have not been removed from the process table.

Have a Unix Problem
Unix Forum - Do you have a UNIX Question?

Unix Books :-
UNIX Programming, Certification, System Administration, Performance Tuning Reference Books

Return to : - Unix System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.
The site www.gotothings.com is in no way affiliated with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.