Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

WHY?!

Name: Anonymous 2012-06-13 13:02


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char **argv){

    int cnt = 0;

    for(int i = 0; i < 10; i++){
        fork();
        cnt++;
    }
    printf("PID:  %d\n", getpid());

    printf("Count:  %d\n", cnt);

    return 0;
}


Copy. Paste. Compile. Run.

I only want 10 childprocess. Why is this?

PS: Yes, I'm new to programming

Name: Anonymous 2012-06-13 14:10

int main(int argc, char * argv[]){
    int cnt;
    int amChild = 0;
    for(cnt = 0; cnt < 10; ++cnt){
        if(!fork()){
            amChild = 1;
            break;
        }
    }
    if(amChild)
        printf("PID:  %d\n", getpid());
    else
        printf("Count:  %d\n", cnt);
    return 0;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List