Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 08-11-2013, 01:04 AM   #1
LQ Newbie
Registered: Aug 2013
Posts: 12

Rep: Reputation: Disabled
Wait ()System Call

Wait system call is where :

The system call wait() is easy. This function blocks the calling process until one of its child processes exits or a signal is received. For our purpose, we shall ignore signals. wait() takes the address of an integer variable and returns the process ID of the completed process. Some flags that indicate the completion status of the child process are passed back with the integer pointer. One of the main purposes of wait() is to wait for completion of child processes.

After Reading above line ,My Question What is critearia of selecting that " One of the child process " .Its is randum ...if so what is use of waiting for a child process to terminate
Old 08-11-2013, 07:29 AM   #2
Senior Member
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060
A different way of saying it: you can control the execution of child processes by call wait() in the parent. wait() forces the parent to suspend execution until the child is finished. wait() returns the process number of the child that finished. If the child finishes before the parent gets around to calling wait(), then when wait() is called by the parent, it will return immediately with the child process number.

Here's a little example that guarantees that the output of the child will precede that of the parent:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <wait.h>
#include <sys/types.h>

void	main	(void)
	if (fork () == 0)
		(void) fprintf (stdout, "this is the child\n");
	else {
		(void) wait ((int *) NULL);
		(void) fprintf (stdout, "this is the parent\n");
Run it:
this is the child
this is the parent
You can have more than one child process by simply calling fork() more than once.
Hope this helps some.

Last edited by tronayne; 08-11-2013 at 07:31 AM.
Old 08-12-2013, 07:47 AM   #3
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

Rep: Reputation: 475Reputation: 475Reputation: 475Reputation: 475Reputation: 475
Moved: This thread is more suitable in Linux-Newbie and has been moved accordingly to help your thread/question get the exposure it deserves.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
wait call in linux hari_sahaya Linux - Newbie 1 06-21-2012 09:12 AM
may i know details about system call how to use system call and definition for virtua mahi rajee Programming 1 05-02-2012 07:45 AM
how to write a system call which returns current system time using call by reference mukul2kul4 Debian 2 09-25-2011 11:17 PM
[SOLVED] In C, select() call does not wait archieval Programming 3 07-22-2010 05:28 AM
tracing the error code returned by wait call lg3 Linux - Software 0 02-21-2005 03:53 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:52 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration