The UNIX and Linux Forums  

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 08:22 PM
Child process is not getting started Crab High Level Programming 5 09-17-2006 06:15 PM
gdb to child process shriashishpatil UNIX for Advanced & Expert Users 4 12-12-2005 04:57 AM
KDM child process larryase UNIX for Dummies Questions & Answers 6 01-24-2005 02:41 PM
Child Process PID skannan High Level Programming 2 06-10-2002 04:54 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 03-19-2006
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
Reply With Quote
Forum Sponsor
  #2  
Old 03-19-2006
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,613
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.
Reply With Quote
  #3  
Old 03-19-2006
Registered User
 

Join Date: Mar 2006
Posts: 106
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.
Reply With Quote
  #4  
Old 03-19-2006
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,613
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.
Reply With Quote
  #5  
Old 03-19-2006
Registered User
 

Join Date: Mar 2006
Posts: 106
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.
Reply With Quote
  #6  
Old 03-20-2006
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
Reply With Quote
  #7  
Old 03-20-2006
Registered User
 

Join Date: Mar 2006
Posts: 106
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 09:56 AM.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
linux

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:12 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0