about child process


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers about child process
# 1  
Old 03-19-2006
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  
Old 03-19-2006
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  
Old 03-19-2006
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  
Old 03-19-2006
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  
Old 03-19-2006
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  
Old 03-20-2006
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  
Old 03-20-2006
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..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

forking a child process and kill its parent to show that child process has init() as its parent

Hi everyone i am very new to linux , working on bash shell. I am trying to solve the given problem 1. Create a process and then create children using fork 2. Check the Status of the application for successful running. 3. Kill all the process(threads) except parent and first child... (2 Replies)
Discussion started by: vizz_k
2 Replies

2. Emergency UNIX and Linux Support

signal between parent process and child process

Hello, everyone. Here's a program: pid_t pid = fork(); if (0 == pid) // child process { execvp ...; } I send a signal (such as SIGINT) to the parent process, the child process receive the signal as well as the parent process. However I don't want to child process to receive the... (7 Replies)
Discussion started by: jackliang
7 Replies

3. Shell Programming and Scripting

script to get child process for a process

!/bin/sh pid=$(ps -Aj | grep MSTRSvr | grep -v grep | awk '{print $1}') sid=$(ps -Aj | grep MSTRSvr | grep -v grep | awk '{print $3}') ps -s "$sid" I am not able to get the desired output it says process list error if i use watch ps -s "$sid" it considers only the first session id (5 Replies)
Discussion started by: schippada
5 Replies

4. Shell Programming and Scripting

[KSH/Bash] Starting a parent process from a child process?

Hey all, I need to launch a script from within 2 other scripts that can run independently of the two parent scripts... Im having a hard time doing this, if anyone knows how please let me know. More detail. ScriptA (bash), ScriptB (ksh), ScriptC (bash) ScriptA, launches ScriptB ScirptB,... (7 Replies)
Discussion started by: trey85stang
7 Replies

5. Shell Programming and Scripting

Child Process Name

Hi , I want to find out the child process name given its PID. I have used the ps command but it displays the parent process name against child PID. Is there any way to find out name of child program executing under any parent program? (1 Reply)
Discussion started by: sneha_heda
1 Replies

6. Shell Programming and Scripting

How to make the parent process to wait for the child process

Hi All, I have two ksh script. 1st script calls the 2nd script and the second script calls an 'C' program. I want 1st script to wait until the 'C' program completes. I cant able to get the process id for the 'C' program (child process) to make the 1st script to wait for the second... (7 Replies)
Discussion started by: sennidurai
7 Replies

7. Programming

Why does my child process not exit?

Im sure it has something to do with the wait() call, but everything ive tried either leaves me with a zombie or with the exec executing indefinitely. switch(pid = fork()) { case -1:perror("fork failed"); exit(1); case 0: if(key == "cd") { execl("/bin/cd", "cd",... (2 Replies)
Discussion started by: p00ndawg
2 Replies

8. UNIX for Dummies Questions & Answers

doubt in child process

fork() system is used to create a child a process.lets consider fork() echo krace will print krace twice .if i give it in loop it will print krace 2 power n time..in this case all child and parent process executes same process ...but i want to create a four different child process to execute four... (4 Replies)
Discussion started by: kracekumar
4 Replies

9. Programming

creating child process

i want to create 3 child processes from the same parent using folk. I know how to use folk but my child processes did not come from the same parent. Any suggestion what i did wrong ? (12 Replies)
Discussion started by: Confuse
12 Replies

10. UNIX for Dummies Questions & Answers

KDM child process

Hello all, I got this little problem. I don't know what happen, but its not stopping work but is more of an FYI. I have this funny process running when I do ps -aef (on RedHat AS3 ) server I get this funny child process. root 2345 1 .... /usr/bin/kdm -nodaemon root... (6 Replies)
Discussion started by: larryase
6 Replies
Login or Register to Ask a Question