xxxxxxxxxx
for val in range(0,5):
if val == 3:
print(exit)
exit()
print(val)
xxxxxxxxxx
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
int main() {
pid_t pid;
int status;
pid = fork();
if (pid == 0) {
// Child process
printf("This is the child process.\n");
// ... (child process execution)
exit(42); // Terminate the child process with status code 42
} else if (pid > 0) {
// Parent process
printf("This is the parent process.\n");
wait(&status); // Parent waits for child to finish and retrieves the status
if (WIFEXITED(status)) {
printf("Child process terminated with status: %d\n", WEXITSTATUS(status));
} else {
printf("Child process terminated abnormally.\n");
}
} else {
// Error while forking
perror("fork");
}
return 0;
}