![]() |
| | #1 |
| Super Moderator Join Date: Sep 2001
Posts: 4,746
| Forking So far, so good - does anyone see any problems with this design? Any thoughts or comments? It's my first larger project in Linux, so I'm running into a lot of new stuff. My main question, however, is about fork'ing and exec'ing. Right now the code is tiny - under 100 lines, and I doubt it'll make it past 150 by the time I'm done. So when I fork, I just have the parent call server(), and the child call client(). Is that bad? Should I put those methods in separate processes and call them through exec()? Are there drawbacks one way or the other? Google only seems to yield man page entries and very simplistic tutorials that don't answer the question! edit: If compiling them in separate files and exec'ing them results in a much smaller "footprint" - I'd definitely like to do it. But if it doesn't make a big different, I'd just rather contain everything to one small file - it's more my style... The code for the client process might grow a little bit, but the server code is going to stay under 20 lines I think... |
| sean is offline | |
| | #2 |
| Registered User Join Date: Mar 2003
Posts: 3,903
| >> ... does anyone see any problems with this design? Sounds good to me. If these nodes are accessed regularly from within each thread of execution, just keep locality in mind for better cache performance. >> I just have the parent call server(), and the child call client(). Is that bad? No. It's ideal. >> call them through exec()? Not unless you have a compelling reason to do so. It's more efficient for the OS to create a new process instance for an image it's already loaded - which includes resolving dynamic libs and other startup fun. gg |
| Codeplug is offline | |
| | #3 | |
| Registered User Join Date: Feb 2003
Posts: 490
| I understand FIFO to mean first-in-first-out. In this context, does it mean anything other than an ordinary queue? Quote:
Also, can either of you point out something better than those simplistic tutorials that talks about appropriate uses for fork()? | |
| R.Stiltskin is offline | |
| | #4 | |||
| Super Moderator Join Date: Sep 2001
Posts: 4,746
| Quote:
Quote:
Quote:
| |||
| sean is offline | |
| | #5 |
| Registered User Join Date: Mar 2003
Posts: 3,903
| I think of forking as just a means for multi-threaded programming. In this case, each "thread" is isolated within a process. One example of this concept in practice is the Google Chrome browser: http://dev.chromium.org/developers/d...process-models How Apache can be configured may be interesting as well: http://httpd.apache.org/docs/2.0/mod/worker.html gg |
| Codeplug is offline | |
| | #6 | |
| Registered User Join Date: Feb 2003
Posts: 490
| Quote:
Codeplug: thanks for those examples. I'm thinking that in a single-processor environment, fork() is useful only when there will be multiple threads (in the abstract sense) of execution, you want each thread to start with a complete copy of the program's state which it can modify, but you don't want those modifications to affect the state of the main program or that of other threads. Does that sound reasonable? Am I overlooking other uses? | |
| R.Stiltskin is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Question about forking with sockets listening | Phoenix_Rebirth | C Programming | 2 | 11-10-2008 04:05 AM |
| Forking Issue... | cookie | Linux Programming | 1 | 07-10-2008 04:46 PM |
| Problem with forking a process | Unitedroad | C Programming | 10 | 10-04-2007 01:43 AM |
| have I got forking problems, or what? | reptonite | C Programming | 8 | 02-23-2006 06:11 PM |
| Forking advice | zee | C Programming | 4 | 06-18-2004 02:35 PM |