#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
void task1() {
printf("Task 1 executing...\n"); // Code for task 1 here
}
void task2() {
printf("Task 2 executing...\n"); // Code for task 2 here
}
void task3() {
printf("Task 3 executing...\n"); // Code for task 3 here
}
void create_child(void (*task)()) {
pid_t pid = fork();
if (pid == 0) {
// Child process
task();
} else if (pid > 0) {
// Parent process
return;
} else {
// Fork failed
}
}
int main() {
create_child(task1);
create_child(task2);
create_child(task3);
// Parent waits for all child processes to finish
for (int i = 0; i < 3; i++) {
wait(NULL);
}
printf("Missions accomplished...\n"); return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHVuaXN0ZC5oPgojaW5jbHVkZSA8c3lzL3dhaXQuaD4KCnZvaWQgdGFzazEoKSB7CiAgICBwcmludGYoIlRhc2sgMSBleGVjdXRpbmcuLi5cbiIpOwogICAgLy8gQ29kZSBmb3IgdGFzayAxIGhlcmUKfQoKdm9pZCB0YXNrMigpIHsKICAgIHByaW50ZigiVGFzayAyIGV4ZWN1dGluZy4uLlxuIik7CiAgICAvLyBDb2RlIGZvciB0YXNrIDIgaGVyZQp9Cgp2b2lkIHRhc2szKCkgewogICAgcHJpbnRmKCJUYXNrIDMgZXhlY3V0aW5nLi4uXG4iKTsKICAgIC8vIENvZGUgZm9yIHRhc2sgMyBoZXJlCn0KCnZvaWQgY3JlYXRlX2NoaWxkKHZvaWQgKCp0YXNrKSgpKSB7CiAgICBwaWRfdCBwaWQgPSBmb3JrKCk7CiAgICBpZiAocGlkID09IDApIHsKICAgICAgICAvLyBDaGlsZCBwcm9jZXNzCiAgICAgICAgdGFzaygpOwogICAgICAgIGV4aXQoMCk7CiAgICB9IGVsc2UgaWYgKHBpZCA+IDApIHsKICAgICAgICAvLyBQYXJlbnQgcHJvY2VzcwogICAgICAgIHJldHVybjsKICAgIH0gZWxzZSB7CiAgICAgICAgLy8gRm9yayBmYW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