Sponsored Content
Full Discussion: fork() in for loop
Top Forums Programming fork() in for loop Post 25980 by Perderabo on Thursday 8th of August 2002 01:09:26 PM
Old 08-08-2002
fork() makes a copy of a process. If you do that in a "for" loop, you have a problem. The first time through the loop you invoke fork() and now you have two processes. Unless you have code to prevent it, both processes with continue to run that loop. On the second iteration you get 4 processes, then 8, then 16, then 32.... Anr 32 processes all forking themselves will put a nasty load on the system.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Fork

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 (5 Replies)
Discussion started by: Deepali
5 Replies

2. Shell Programming and Scripting

Endless loop - Fork function failed?

I need a quick script that will serve as a sort of "real time monitor" for watching some log files. I am using Bourne shell in HP-UX 10.20. I have basically created a script that never ends, unless of course I manually terminate it. Here's the script (it's called qhistory): clear echo "REAL... (3 Replies)
Discussion started by: cdunavent
3 Replies

3. Programming

fork() fd

I run this code, actually I want to both processes print the message from "data". But only one does. What happens? Anyone can help? #include <stdio.h> main(){ int fd, pid; char x; fd = open("data",0); /* open file "data" */ pid = fork(); if(pid != 0){ wait(0); ... (2 Replies)
Discussion started by: Herman
2 Replies

4. Programming

Fork ()

hi all About this code for (i = 1; i < n; i++) if ((childpid = fork()) <= 0) break; I really can't understand the output . and the way fork () return the value . how about the process Id ,the child process Id and the parent ID in this case so please answer me soon (5 Replies)
Discussion started by: iwbasts
5 Replies

5. Programming

fork() help

Hi everybody, I wanna write a code to understand how fork works. my target -------------- -Parent creates a file(called temp) and writes into this file "1".Then it closes the file. -Then parent creates a child and wait until execution of this child ends. -Then child opens the same... (3 Replies)
Discussion started by: alexicopax
3 Replies

6. Shell Programming and Scripting

Inifinite Loop on fork

I am trying to ping through a list of devices in parallel. When the code below is executed, I enter a infinite loop. I want to used the number of lines in the file as my boundry. I am a perl rookie and just cant see whats wrong. would appreciate help ... use Net::Ping; # $filename... (0 Replies)
Discussion started by: popeye
0 Replies

7. Programming

IPC-using fork() in a loop

I need to write a program which creates some n number of processes first and also creates a fifo for each of them, then it connects to the server and.. I tried creating these processes with fork() in a for loop but it doesn't print out what i write inside the child.. for(int count = 0; count... (7 Replies)
Discussion started by: saman_glorious
7 Replies

8. Programming

C Socket Client/Server Fork Loop

Hello people. I'm trying to do something like a search engine. Server runs in the background by using ./server & which has data from a textfile stored in an array. Client then runs by using ./client It will then prompt "Search for:" For example, if I searched for Products called Instant... (0 Replies)
Discussion started by: andylbh
0 Replies

9. UNIX for Dummies Questions & Answers

fork()

I'm trying to run a simple test on how to use fork(), i'm able to execute the child process first then the parent, but how can I execute parent then child..? Thanks! (1 Reply)
Discussion started by: l flipboi l
1 Replies

10. Programming

Fork!

I understand that fork create a child but I need very simple example that make child useful.... I mean how will make the program faster anyone explain with code plz using C plz (2 Replies)
Discussion started by: fwrlfo
2 Replies
RENDEZVOUS(2)							System Calls Manual						     RENDEZVOUS(2)

NAME
rendezvous - user level process synchronization SYNOPSIS
#include <u.h> #include <libc.h> ulong rendezvous(ulong tag, ulong value) DESCRIPTION
The rendezvous system call allows two processes to synchronize and exchange a value. In conjunction with the shared memory system calls (see segattach(2) and fork(2)), it enables parallel programs to control their scheduling. Two processes wishing to synchronize call rendezvous with a common tag, typically an address in memory they share. One process will arrive at the rendezvous first; it suspends execution until a second arrives. When a second process meets the rendezvous the value arguments are exchanged between the processes and returned as the result of the respective rendezvous system calls. Both processes are awakened when the rendezvous succeeds. The tag space is common to processes in the same file name space, so rendezvous only works between processes in the same file name space. If a rendezvous is interrupted the return value is ~0, so that value should not be used in normal communication. SOURCE
/sys/src/libc/9syscall SEE ALSO
segattach(2), fork(2) DIAGNOSTICS
Sets errstr. BUGS
The correlation of rendezvous tags and file name space is a historical accident. If two unrelated processes happen to be in the same name space and do a rendezvous, trouble will result. The solution is to call rfork(RFNAMEG) (see fork(2)) in programs that use rendezvous unless they need to share the name space with their parent. This is especially important in Alef programs. RENDEZVOUS(2)
All times are GMT -4. The time now is 12:20 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy