Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
google site



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 !!

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Search this Thread
  #1  
Old 03-20-2001
Registered User
 

Join Date: Mar 2001
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
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
Sponsored Links
  #2  
Old 03-20-2001
PxT's Avatar
PxT PxT is offline Forum Advisor  
Registered User
 

Join Date: Oct 2000
Location: Sacramento, CA
Posts: 909
Thanks: 0
Thanked 0 Times in 0 Posts
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  
Old 03-20-2001
Neo's Avatar
Neo Neo is online now Forum Staff  
Administrator
 

Join Date: Sep 2000
Location: Asia Pacific
Posts: 7,840
Thanks: 28
Thanked 43 Times in 21 Posts
"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  
Old 08-21-2001
wee wee is offline
Registered User
 

Join Date: Aug 2001
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
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  
Old 08-23-2001
patvdv's Avatar
Registered User
 

Join Date: Jul 2001
Location: Belgium
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Threading

I thibk you should do some reading on how write threaded programs.
  #6  
Old 08-26-2001
rwb1959's Avatar
Registered User
 

Join Date: Aug 2001
Location: Virginia, USA
Posts: 438
Thanks: 0
Thanked 0 Times in 0 Posts
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
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
fork() help alexicopax Programming 3 03-08-2007 03:08 AM
shm sem fork etc... Please help Dana73 Programming 1 02-28-2006 07:51 AM
Fork () iwbasts Programming 5 11-09-2005 03:39 AM
Fork or what? crippe Programming 0 03-08-2005 04:21 AM
fork() MKSRaja Programming 2 02-07-2005 10:55 AM



All times are GMT -4. The time now is 11:21 PM.