Sponsored Content
Full Discussion: multiple fork() question
Top Forums Programming multiple fork() question Post 302492996 by pludi on Wednesday 2nd of February 2011 04:53:04 AM
Old 02-02-2011
When forking, a new process is created, and from that point on the kernels process scheduler decides in which order to run the processes. With enough (allocated) CPUs all may run at the same time. With lesser CPUs it's probably randomized, depending on system load.

Depending on what your application does there are different ways to "order" your output:
  • If it's mostly calculation take a look at OpenMP.
  • If you're (for example) communicating over a network, have the children, except for the first one, save the output until they receive a signal from the parent thread (using wait, signal, and kill)
 

10 More Discussions You Might Find Interesting

1. Programming

simple fork question

When executing this simple program: #include <unistd.h> void main() { int f; printf("\n Parent procces ID=%d\n",getpid()); f=fork(); if(f==0) { printf("\n Child process ID=%d father=%d\n",getpid(),getppid()); } ... (2 Replies)
Discussion started by: bb666
2 Replies

2. Programming

fork multiple shells

Hi, i was trying to play with fork,exec and signal for spawning multiple new shells, but it seems that i'm doing blunder somewhere. <sample code> 1 /* 2 * The idea is to fork multpile(equal to $ULIMIT) childs 3 * and replace their images with process:csh 4 * during this the parent... (3 Replies)
Discussion started by: amit4g
3 Replies

3. Programming

A small question about fork()

Hello experts, I am using fork() in my code but I am confused which output comes first child or parent? I did the following code .My book shows parent first but my linux shows child first.Can anyone tell me why? #include <stdio.h> int main(){ int pid; printf("I am original process with pid... (5 Replies)
Discussion started by: mlhazan
5 Replies

4. Programming

Multiple process using fork()

I have a code which has four different process, each printing different message. I have provided it with user input (implemented using thread), depending on which the corresponding message from that process has to be printed.The code is shown below.when I run the pgm, it takes input such as... (1 Reply)
Discussion started by: shashi
1 Replies

5. Programming

Question About Multi-Processed Applications... fork()

Assume we have an application built on *nix that uses fork()...then the processes procedure is going to act as follow: X is considered a parent process (first click on application) Y is considered a child process of X (second click on application) Z is considered a child process of Y (third... (6 Replies)
Discussion started by: f.ben.isaac
6 Replies

6. Programming

Need help with fork, forking multiple childs and shared memory

Hi all, I m writing an application, where i need to fork multiple childs and those child should handle particular task given to them. More descriptive. For example, suppose i have 4 Network, each network has multiple nodes. Now on the basis of network child should be forked and these child... (8 Replies)
Discussion started by: helpmeforlinux
8 Replies

7. Programming

Beginners question about fork

Hi everyone: I'm developing a dynamic library for notifications, this library is used for a daemon that i've programmed, when something goes wrong the library should send an email to an administrator, but since sending an email is a non-vital process then it can fail (it should work as an... (4 Replies)
Discussion started by: edgarvm
4 Replies

8. Programming

question about fork

i'm experimenting fork function and i found this code #include <stdio.h> #include <sys/stat.h> #include <sys/types.h> #include <wait.h> #include <fcntl.h> #include <unistd.h> int main(void) { int fd; pid_t p; p = fork(); fork(); if (p>0) { fork();} fork(); fork();... (6 Replies)
Discussion started by: blob84
6 Replies

9. Programming

Linux fork, execv, wait question

Hi All, I have a program for class that needs to do the following: 1. Print the directory entries from the current directory using ncurses 2. Provide a prompt next to each directory entry and allow the user to enter commands that may or may not be about the file 3. Execute those commands in... (1 Reply)
Discussion started by: afulldevnull
1 Replies

10. UNIX for Beginners Questions & Answers

One parent, multiple children pipe with fork()

The task I have to do is something along the lines "I receive some input and based on the first character I send it through pipe to one of the children to print". The scheme it is based on is 1->2; 1->3; 1->4; 2 will print all the input that starts with a letter, 3 will print all the input that... (2 Replies)
Discussion started by: Ildiko
2 Replies
qpsmtpd-prefork(8)					      System Manager's Manual						qpsmtpd-prefork(8)

NAME
qpsmtpd-prefork - Preforkin server for qpsmtpd SYNOPSIS
qpsmtpd-prefork [options] DESCRIPTION
qpsmtpd-prefork is the qpsmtpd frontend script which binds to the SMTP TCP socket, and asynchronously forks new children in advance of new connections. OPTIONS
--port port Binds to a specific port, instead of the default 2525. --user user On startup, switch to run as user instead of the starting user. Applies only when started as root (as is normal when listening on port 25). --limit-connections limit Accept at most limit simultaneous connections. Inbound connections beyondthis limit will be deferred or refused. --max-from-ip limit Accept at most limit simultaneous connections from any given IP address; does not override --limit-connections, if set. --children limit Limit the total number of child processes to limit; once all children are handling requests, further connections are deferred. --idle-children count Keep count child processes available, subject to the upper bound given via --children. Specify 0 to disable preforking entirely. --interface addr Bind to the local address addr, instead of the default behavior of binding to all interfaces. Can be specified multiple times to bind to more than one interface or local address. --renice-parent delta Adjust the priority of the parent process by delta, yielding more CPU time to other processes. The default is 5. --detach Detach from the controlling terminal at startup, to run as a standalone daemon. See also --pid-file. --pid-file filename Upon startup, and after daemonizing if applicable, write the process ID to filename, for use by sysvinit control scripts or similar utilities. --pretty-child Update child process names within the process table. --version Print the qpsmtpd release version and exit. --debug Be somewhat more verbose about logging during startup (has no effect once fully started). --help Display commandline help and exit. AUTHOR
Copyright (c) 2006, SoftScan; based on qpsmtpd-forkserver by Ask Bjorn Hansen <ask@develooper.com> http://smtpd.develooper.com/ qpsmtpd-prefork(8)
All times are GMT -4. The time now is 05:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy