Programming help..
A
/ | \
B C D
/ \ \
E F G
For our assignment we are supposed to (in writing) say how we can perform the creation of said processes using 6, 5, 4, and 3 fork calls. I can understand 6 calls easy enough, but I am a little confused on how to accomplish it with less.
My basic thought is to do the initial fork, then if the pid is 0 do some condition to fork again.. but I am a little confused. Any help would be appreciated. I don't need the code, and I don't need all of the solved, just a little push in the right direction.
Name:
Anonymous2011-11-03 1:58
Formatting is off, sorry.
A is parent to B C D. B has no children, C has children E and F, D has child G.
Here is a dot version of your directed acyclic graph
File: fork.dot digraph Hierarchy {
rankdir=TB;
"A"->"B";
"A"->"C";
"A"->"D";
"C"->"E";
"C"->"F";
"D"->"G";
}
Well if it's just in writing, describe a fork that can fork more than one child at once.
Name:
Anonymous2011-11-03 5:17
NAME
spork -- generate a random process
SYNOPSIS
#include <cutlery.h>
void
spork(void);
DESCRIPTION
spork() generates a new, random process by blending
characteristics from the calling process and the process
which most recently invoked spoon() in the current
process group. These characteristics may include any or
all of the following:
* Current working directory
* Open file descriptors, directory streams, and
memory-mapped files (open(2), opendir(3), mmap(2))
* Environment variables
* Memory and record locks (mlock(2), flock(2))
* Resource limits
Pending asynchronous I/O operations, semaphores, and
timers are not inherited by the spork()ed process.
Threading behaves similarly to fork(), i.e. handlers
defined with pthread_atfork(3) in both the fork() and
spoon() processes are invoked when calling spork().
RETURN VALUES
spork() returns 0 on success, and nonzero on error.
ERRORS
spork() will fail and subsequent spork() will fail if:
[ENOMEM] Not enough memoory is available to create
the task structure for the new process.
SEE ALSO
execve(2), fork(2), spoon(2)
HISTORY
A spork() function call appeared in Anonix Prerelease -7.