What does this C-code do (OS class)?

We need to explain what this C-code does but i dont really get the hang of it.

Especially at that for loop where it breaks. anybody cares to explain? it would be of great help?

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

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

pid_t childpid = 0;

int i, n;

if (argc != 2){ /* check for valid number of command-line arguments */

fprintf(stderr, "Usage: %s processes\n", argv[0]);

return 1;

}

n = atoi(argv[1]);

for (i = 1; i < n; i++)

if (childpid = fork())

break;

fprintf(stderr, "i:%d process ID:%ld parent ID:%ld child ID:%ld\n",

i, (long)getpid(), (long)getppid(), (long)childpid);

return 0;

}

Update:

EDIT

sorry for the above edit^ it was an error

Please enter comments
Please enter your name.
Please enter the correct email address.
You must agree before submitting.

Answers & Comments


Helpful Social

Copyright © 2024 QUIZLS.COM - All rights reserved.