what are parent and child processes all about?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers what are parent and child processes all about?
# 1  
Old 04-25-2002
what are parent and child processes all about?

I don't follow what these are...

this is what my text says...

"When a process is started, a duplicate of that process is created. This new process is called the child and the process that created it is called the parent. The child process then replaces the copy for the code the parent process created with the code the child process is supposted to execute."

The last sentance confuses me the most. Actually the entire thing confsues me. Why is a child process started anyways? Why does the parent process spawn a child process in the first place? And what's all this code copy stuff all about?

The next paragraph states...

"While the command is executing, the shell waits until the child process has completed. After is completes, the parent process terminates the child process, and a prompt is displated, ready for a new command"

Why does this happen? I guess it goes back to my confusion about why the child process is created in the first place.
# 2  
Old 04-26-2002
Good example.

When you use a command like grep or find, they kick off subprocesses (children processes) that actually do the work.

EXAMPLE #1
The parent ( the command that you typed.) "find . -name somefile -print " kicks off subprocesses that actually go out and search for the file that you specified. When they are done they report back to the find command.

EXAMPLE #2
Using grep if you are trying to do something like matching a pattern(s) in a file to print out the lines.

cat filename|grep patterna

This command will actually spawn 2 processes. The cat command, the parent, and the grep command, the child. When the child (grep) finishes it returns to the parent (cat) with the result.

Example #3
Do a ps -aef |grep sh" to find your telnet session. Find your login and do a ps -aef |grep on that PID. All of your commands are technically children of your telnet session as you will see.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Kill Parent/ Child processes

I am trying to kill PIDs that are tied to a KSH "load_sqlplus" and I am using the below code LIST_PID=`ps -ef | grep -i "load_sqlplus" | grep -v grep | awk '{print $2}'` if ; then echo "Processes killed" "PID : " $LIST_PID kill -9 $LIST_PID else echo "Nothing to Kill" fi... (4 Replies)
Discussion started by: venky338
4 Replies

2. 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

3. Programming

fork(), parent and child processes???

Hi friends, I have a small question regarding unix system call fork, I hope you will solve my problem. Here is the small program $ cat fork1.c #include <stdio.h> #include <unistd.h> #include <sys/types.h> int main() { int pid; int x = 0; x = x + 1; pid = fork(); if(pid < 0) {... (2 Replies)
Discussion started by: gabam
2 Replies

4. Homework & Coursework Questions

Need help with deleting childīs parent and child subprocess

1. The problem statement, all variables and given/known data: I need to make an program that in a loop creates one parent and five children with fork(). The problem i'm trying to solve is how to delete the parent and child of the childīs process. 2. Relevant commands, code, scripts,... (0 Replies)
Discussion started by: WhiteFace
0 Replies

5. Shell Programming and Scripting

Creating a pipe using parent and child processes

Hello, I am trying to create a pipe that will direct stdout to in side of the pipe, and stdin to the out side of the pipe - I created two child processes to handle this. However, my pipe doesn't seem to be working correctly. Did I use execv() correctly? Command1 and command2 represent the two... (3 Replies)
Discussion started by: jre247
3 Replies

6. UNIX for Dummies Questions & Answers

Kill child processes, when parent is "bash"

Consider this simple command line bash -c 'echo $$ ; sleep 10000'This will print the newly created bash PID and sleep for a long time. If I go to another terminal and do something like ps -flax | grep leepI'll see something like 501 92418 91910 0 0:00.00 ttys000 0:00.00 bash -c echo $$... (5 Replies)
Discussion started by: teras
5 Replies

7. UNIX for Advanced & Expert Users

How to find all the child processes of a parent process

Hi I am trying to see if there are some options in ps command or if there is a shell script which basically shows you all the processes spawned by a parent process , then all the processes of its child processes and so on down the hierarchy may be like a tree structure. It might be a generic... (6 Replies)
Discussion started by: clifford
6 Replies

8. Shell Programming and Scripting

Parent/Child Processes

Hello. I have a global function name func1() that I am sourcing in from script A. I call the function from script B. Is there a way to find out which script called func1() dynamically so that the func1() can report it in the event there are errors? Thanks (2 Replies)
Discussion started by: yoi2hot4ya
2 Replies

9. UNIX for Dummies Questions & Answers

kill parent and child

Hello all, I have gone through the search and looked at posting about idle users and killing processes. Here is my question I would like to kill an idle user ( which I can do) but how can I asure that all of his process is also killed whit out tracing his inital start PID. I have tried this on a... (4 Replies)
Discussion started by: larry
4 Replies

10. Filesystems, Disks and Memory

How hard can it be? ps child/parent

:( Since I'm fairly new to the scene and don't have much experience in shell programming, I decided to check out the net for a useful script or two. What I'm looking for is a script that would let me enter a PID and then show the process tree associated with it. So it would display the (grand-)... (2 Replies)
Discussion started by: velde046
2 Replies
Login or Register to Ask a Question