LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 08-11-2013, 02:04 AM   #1
Sud_paddy
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, 08:29 AM   #2
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,476

Rep: Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020
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:
Code:
#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");
	}
	exit (EXIT_SUCCESS);
}
Run it:
Code:
prog
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 08:31 AM.
 
Old 08-12-2013, 08:47 AM   #3
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

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


Reply


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 10: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 08:45 AM
how to write a system call which returns current system time using call by reference mukul2kul4 Debian 2 09-26-2011 12:17 AM
[SOLVED] In C, select() call does not wait archieval Programming 3 07-22-2010 06:28 AM
tracing the error code returned by wait call lg3 Linux - Software 0 02-21-2005 04:53 AM


All times are GMT -5. The time now is 01:51 PM.

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