EmbLogic's Blog

c program to pause the process using system call “wait()”

 

RCS file: header.h,v
Working file: header.h
head: 1.4
branch:
locks: strict
	root: 1.4
access list:
symbolic names:
keyword substitution: kv
total revisions: 4;	selected revisions: 4
description:
it includes all the header files
----------------------------
revision 1.4	locked by: root;
date: 2015/02/25 17:38:38;  author: root;  state: Exp;  lines: +1 -0
<wait.h> is used to pause parent process using wait()
----------------------------
revision 1.3
date: 2015/02/25 17:23:47;  author: root;  state: Exp;  lines: +1 -0
<stdlib.h> is used for EXIT_FAILURE
----------------------------
revision 1.2
date: 2015/02/25 17:16:20;  author: root;  state: Exp;  lines: +1 -0
<sys/types.h> is used for variable f_ret whose datatype is pid_t
----------------------------
revision 1.1
date: 2015/02/25 17:14:14;  author: root;  state: Exp;
Initial revision
=============================================================================

RCS file: wait.c,v
Working file: wait.c
head: 1.6
branch:
locks: strict
	root: 1.6
access list:
symbolic names:
keyword substitution: kv
total revisions: 6;	selected revisions: 6
description:
It is a program to pause the parent process using system call wait and to run the parent process again after the child process is finished
----------------------------
revision 1.6	locked by: root;
date: 2015/02/25 17:44:33;  author: root;  state: Exp;  lines: +4 -2
I have taken a int variable exit_code which will be returned by the exit to the location pointed by the wch contains the exit code and the PID of the last child process executed
----------------------------
revision 1.5
date: 2015/02/25 17:39:07;  author: root;  state: Exp;  lines: +19 -2
Previously parent process was terminating before the child process ...as a result there is no one to execute the termination section of the child process and the child is now an orphan child
so to overcome this i have used a system call wait in which the parent process is paused and the child process is initially finished and after that parent process is terminated .
So that the shell will not be hanged.
----------------------------
revision 1.4
date: 2015/02/25 17:29:31;  author: root;  state: Exp;  lines: +10 -0
Here i have declared a int variable n which have unique values for both parent and child process.
And i am running both the parent and child processes for the given value of n using for loop.
----------------------------
revision 1.3
date: 2015/02/25 17:24:10;  author: root;  state: Exp;  lines: +16 -0
Now i have taken 3 cases using switch statement 
First case is when f_ret is a negative value,it will print an error
Second case is when f_ret is zero , then it is a child process.
Else it is a parent process.
----------------------------
revision 1.2
date: 2015/02/25 17:17:08;  author: root;  state: Exp;  lines: +3 -0
Here i have declared a variable f_ret whose datatype is pid_t
After that i have created a child process using fork() 
Here fork is returning two values which will be copy on right in the f_ret
One value is for parent process and that value will be the PID of the child process.
Another value will be 0 when fork() is executed by the child process
----------------------------
revision 1.1
date: 2015/02/25 17:14:14;  author: root;  state: Exp;
Initial revision
=============================================================================

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>