week 10
week 10
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>
int main() {
pid_t pid;
int status;
pid = fork();
if (pid < 0) {
perror("fork");
exit(EXIT_FAILURE);
} else if (pid == 0) {
// Child process
exit(EXIT_SUCCESS);
} else {
// Parent process
} else if (WIFSIGNALED(status)) {
return 0;
The waitid() system call is used to wait for the termination of a specific
process or any child process. It provides more flexibility than wait() or
waitpid() by allowing the caller to specify various options and receive
detailed information about the terminated process.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>
int main() {
pid_t pid;
int status;
siginfo_t info;
pid = fork();
if (pid < 0) {
perror("fork");
exit(EXIT_FAILURE);
} else if (pid == 0) {
// Child process
exit(EXIT_SUCCESS);
} else {
// Parent process
perror("waitid");
exit(EXIT_FAILURE);
return 0;
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>
int main() {
pid_t pid;
int status;
pid = fork();
if (pid < 0) {
perror("fork");
exit(EXIT_FAILURE);
} else if (pid == 0) {
// Child process
exit(EXIT_SUCCESS);
} else {
// Parent process
perror("waitpid");
exit(EXIT_FAILURE);
if (WIFEXITED(status)) {
return 0;
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/resource.h>
int main() {
pid_t pid;
int status;
pid = fork();
if (pid < 0) {
perror("fork");
exit(EXIT_FAILURE);
} else if (pid == 0) {
// Child process
exit(EXIT_SUCCESS);
} else {
// Parent process
return 0;
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/resource.h>
int main() {
pid_t pid;
int status;
pid = fork();
if (pid < 0) {
perror("fork");
exit(EXIT_FAILURE);
} else if (pid == 0) {
// Child process
exit(EXIT_SUCCESS);
} else {
// Parent process
return 0;