The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Can a child process return a specific value to a parent process ? Ametis1970 High Level Programming 8 04-09-2008 11:22 PM
Child process is not getting started Crab High Level Programming 5 09-17-2006 09:15 PM
gdb to child process shriashishpatil UNIX for Advanced & Expert Users 4 12-12-2005 07:57 AM
KDM child process larryase UNIX for Dummies Questions & Answers 6 01-24-2005 05:41 PM
Child Process PID skannan High Level Programming 2 06-10-2002 07:54 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-19-2006
compbug compbug is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 26
Question about child process

hello every one,

i want to know more about creation of child process.

UNDER WHAT CIRCUMSTANCES child process is created?
WHAT ARE THE PREREQUISITES for a child process to be created?

let us say we have a prog.c, prog.obj(compiled.c),.a\.out files.


is any child PROCESS CREATED from the beginning to the execution of .a.out file
in the above example


please give me clear explanation



thanks for your time
  #2 (permalink)  
Old 03-19-2006
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
A child process is created by the fork() system call. So if prog.c correctly calls fork() it will generate a child process. It might indirectly call fork() by doing something like this:
system("date");
The system() function creates a child process which will exec() a shell. Then the shell will run the date command.

A correct call to fork() can fail if there are too many processes already running or something like that.
  #3 (permalink)  
Old 03-19-2006
amro1 amro1 is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 105
child proc.

all child processes are created in two steps:
1. system creates the exact copy of parent process (by fork)
2. the code of the parent process is substituted within a code of the child process.

as a consequence the child process inherits all the environment of the parent process (all the system variables , viewable with "env" command). This scheme is universal for all versions of unix/linux.
Get "UNIX Essentials and UNIX Core" DVD course if you have questions like that.
  #4 (permalink)  
Old 03-19-2006
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
Actually, that step 2 is describing what happens when an exec() system call is invoked. This is usually what happens. But exec() and fork() are different. Some programs fork() but then do not exec(). An example is an ftpd server not running under inetd (which is how we run pureFTPD). When it gets a connection, it forks and lets the child handle that session.
  #5 (permalink)  
Old 03-19-2006
amro1 amro1 is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 105
ftpd

ftpd uses tcp and all tcp servers/deamons lunch new instances as request comes (disregarding of implementation). It does not exec not because it is exception but because it saves and extra operation as the next operation would be to load another instance of FTPd again, to save an extra step it does not exec.
  #6 (permalink)  
Old 03-20-2006
compbug compbug is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 26
Advantage Of Child Process

when a parent process can do its job efficiently why do we need the over head to invoke some other process to perform the task on its behalf?

are there any system performance, advantages in invoking a child process?


thanks for your replys in advance
  #7 (permalink)  
Old 03-20-2006
amro1 amro1 is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 105
here...

no, there's obviosly no system perfomance advantages sinse new process gets new resourses and take extra CPU time. Not all subsystems spawn new processes but only these that had been developed to. For example ftpd waits for connection it gets an connection and gives the way for a next connection. It does it by creating a new instance of itself while the old instance is occupied with an previos connection. If service is heavily depended on spawing there is limit in configuration for number of simultaniously working instances of one program. You can visit /etc/initd.conf or /etc/xinitd.conf and see the service "wait =no", or "respawn" for these services that will not wait for end of previos transaction to startnew one. By convension, all TCP services for example are "no wait". I learn with "UNIX Essentials and UNIX Core" DVD and with Emi Nemet book.
Hope it helps.

Last edited by amro1; 03-20-2006 at 12:56 PM..
Sponsored Links
Closed Thread

Bookmarks

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:28 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0