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
fork() help alexicopax High Level Programming 3 03-08-2007 12:08 AM
shm sem fork etc... Please help Dana73 High Level Programming 1 02-28-2006 04:51 AM
Fork () iwbasts High Level Programming 5 11-09-2005 12:39 AM
Fork or what? crippe High Level Programming 0 03-08-2005 01:21 AM
fork() MKSRaja High Level Programming 2 02-07-2005 07:55 AM

Closed Thread
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-20-2001
Registered User
 

Join Date: Mar 2001
Posts: 2
What is a fork? Why would one create a fork? What are the advantages and disadvantages of using a fork?

Please advise.

Thank You.

Deepali
Forum Sponsor
  #2 (permalink)  
Old 03-20-2001
PxT's Avatar
PxT PxT is offline
Registered User
 

Join Date: Oct 2000
Location: Sacramento, CA
Posts: 905
Advantages of using a fork? You dont get spaghetti sauce on your hands....

Please read the <A HREF="http://www.rahul.net/cgi-bin/userbin/man?topic=fork&section=2">fork(2)</A> man page. It should answer most of your questions.
  #3 (permalink)  
Old 03-20-2001
Neo's Avatar
Neo Neo is offline
Administrator
 

Join Date: Sep 2000
Location: Asia Pacific
Posts: 4,189
"To Fork" is like "a fork in your path" when you are walking in the forest. The concept is similar in UNIX processes, however the fork occurs with the logic flow of the program and processes.

Consider that your process is running as process ID 100. The process has an open file descriptor listening for incoming TCP/IP connections. When an incoming connection occurs, the process could "fork" another process to handle the incoming connection. The process ID, for example, of the new process that was "forked" could be 132 (whatever the next available process ID was).

When a new process is forked it has a few interesting options. One is to take the content of the global variables and other data structures and make a copies in the new fork. Another option is to fork and completely replace the original process.

So, forking is just something that occurs to a process in its "path of execution". The main difference between forking processes and your fork as your walk down the road is that you can't physically walk down two paths. Software processes can and do spawn many processes by forking.

Hope this helps.

[Edited by Neo on 03-20-2001 at 06:27 PM]
  #4 (permalink)  
Old 08-20-2001
wee wee is offline
Registered User
 

Join Date: Aug 2001
Posts: 1
Question Fork

Hi,
I'm new to programming under unix too, and I'm trying to implement a load balancing system for web traffic.

The idea is this,
I have a single web server running on PC A, and I have 5 other PCs (PC B - PC F) running only mysql servers. Assuming all the databases contain synchronized data, I would like to implement a database search facility where the web server receives the input, split the input keywords into single keywords and using fork() in the cgi-script, spawn multiple child processes to issue seperate queries to each of the database servers via different connection strings to receive the result.

Will this result in a much faster response time than just running a single database server and searching all the keywords serially ?
Is there a better way to do it besides forking ? What are the drawbacks of forking and implementing it this way ?

Sample code would very much be appreciated.
Thanks,
Wee
  #5 (permalink)  
Old 08-23-2001
patvdv's Avatar
Registered User
 

Join Date: Jul 2001
Location: Belgium
Posts: 83
Threading

I thibk you should do some reading on how write threaded programs.
__________________
Patrick Van der Veken - UNIX consultant (c) 2001 - 2001 http://www.baanboard.com - http://www.ux-core.com
'True strength lies in gentleness' - Irish proverb
  #6 (permalink)  
Old 08-26-2001
rwb1959's Avatar
Registered User
 

Join Date: Aug 2001
Location: Virginia, USA
Posts: 438
forking

Wee,

Yes you could use fork() BUT...
I would also recommend using threads to
accomplish what you are proposing. If you were
to use fork(), you would have as many separate
programs running as you have keywords per query.
Then, you would have to synchronize the results
of each into a single result. Threads will allow
you to run each keyword query against separate
databases but still allow you to synchronize
the results from within the same program. I
would recommend reading...

"Programming with POSIX Threads"
ISBN 0-201-63392-2

"Pthreads Programming"
ISBN 1-56592-115-1
Google UNIX.COM
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:58 AM.


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

Content Relevant URLs by vBSEO 3.2.0