|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 !! |
![]() |
|
|
Search this Thread |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
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§ion=2">fork(2)</A> man page. It should answer most of your questions. |
|
#3
|
||||
|
||||
|
"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
|
|||
|
|||
|
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
|
||||
|
||||
|
Threading
I thibk you should do some reading on how write threaded programs.
|
|
#6
|
||||
|
||||
|
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 | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
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 |