LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Closed Thread
  Search this Thread
Old 09-15-2008, 03:14 PM   #1
LinuxInfo
LQ Newbie
 
Registered: Sep 2008
Posts: 21

Rep: Reputation: 15
Need some information on fork() and advantages of having children.


Respected Sir,

I need some information on fork() and advantages of having more children.

Please help me with this.

Thanks.

Last edited by XavierP; 09-15-2008 at 05:45 PM.
 
Old 09-15-2008, 03:33 PM   #2
bscarrier
LQ Newbie
 
Registered: Nov 2006
Posts: 3

Rep: Reputation: 0
Wink fork() and children

fork() is a very useful way of parallel programming by using the operating system to do the hard work for you.
fork() copies your current process and gives the new process a different process id. The new process is a child of the original program.
The only difference is the return value of the fork() function call. The result indicates whether the current process is the parent or child.
BE CAREFUL , the processes are identical, all variables are shared and therefore if you want to change a variable without conflict you will need to use semaphores.
I have mainly used fork() to run off-line calculations (that require no user interaction) whilst allowing the parent process to monitor user input to start other parallel calculations or cancel processes if required.
 
Old 09-15-2008, 04:13 PM   #3
Eilya
Member
 
Registered: Aug 2008
Posts: 52

Rep: Reputation: 15
Dear LinuxInfo,

As bscarrier mentioned it is so useful and .... fork() makes a child which is alive until its parent is alive and it is so useful for multiprocessing which makes Linux so powerful, in windows we have Spawn which allows to run two separate processes simultaneously(for example we run ls and main simultaneously) but in Linux we dont have such a thing we have to build it by a fork and an exec, moreover in this trend we have to pay attention to prevent making zombies(which is not good for us) moreover It is useful to know by one fork() we have 2 processes simultaneously, by two fork()s we have 4 processes simultaneously, and ... so we have this trend: processes = 2 ^ (Number of Fork()s).

Spawn
.
|
|
-----
| |
| |
ls main
| |


fork()
.
|
|
-----
| |
| |
ls ls
| |



Regards,
Eilya
 
Old 09-15-2008, 05:46 PM   #4
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

Rep: Reputation: 475Reputation: 475Reputation: 475Reputation: 475Reputation: 475
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.

Continue here: http://www.linuxquestions.org/questi...ildren-670059/
 
  


Closed 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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need information on fork() and advantages of having more children? LinuxInfo Programming 3 09-15-2008 12:17 PM
Need information on fork() and advantages of having more children LinuxInfo General 2 09-15-2008 11:54 AM
Need some information on fork() and advantages of having children. LinuxInfo Linux - General 2 09-15-2008 11:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:54 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
Open Source Consulting | Domain Registration