Howdy, Stranger!

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

Categories

fork()ing Inside a Loop

z0diac_12z0diac_12 Member Posts: 35
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

  • tuxfoodtuxfood Member Posts: 2
    : 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.