31 lines
730 B
C
31 lines
730 B
C
#include <unistd.h>
|
|
#include <stdio.h>
|
|
#include <sys/types.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
|
|
int main() {
|
|
for (int start = 0; start < 50; start += 10) {
|
|
pid_t pid = fork();
|
|
if (pid == -1) {
|
|
fprintf(stderr, "Error forking: %s\n", strerror(errno));
|
|
return 1;
|
|
} else if (pid == 0) {
|
|
// I AM FORK!
|
|
for (int i = start; i < start + 10; i++) {
|
|
printf("%d: %d\n", pid, i);
|
|
}
|
|
printf("Fork %d finished counting from %d\n", getpid(), start);
|
|
return 0;
|
|
} else {
|
|
printf("Fork %d successfull\n", pid);
|
|
}
|
|
}
|
|
|
|
|
|
fork();
|
|
fork();
|
|
fork();
|
|
printf("Hello World\n");
|
|
}
|