fork()ing Inside a Loop

Hi,

[code]
while (1) {
if (fork()) {
...
} else {
...
}
}
[/code]

In the above snippet of code, fork() executes only once. Why is this happening? Shouldn't the code fork off infinite child processes?

Please enlighten.

z0diac_12

Comments

  • : Hi,
    :
    : [code]
    : while (1) {
    : if (fork()) {
    : ...
    : } else {
    : ...
    : }
    : }
    : [/code]
    :
    : In the above snippet of code, fork() executes only once. Why is this happening? Shouldn't the code fork off infinite child processes?
    :
    : Please enlighten.
    :
    : z0diac_12
    :
    :


    hi...

    maybe u could include the header file errno.h (#include)

    and check whether any error occurs during forking ..

    check it using perror() function ..

    use it immediately after fork()

    just call perror like perror("fork");

    If any error is there it will print it as

    fork: < THe error goes here >

    hope this helps


    bye

    tuxfood
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion