229J07 Report
229J07 Report
Date :2025-03-27
Experimental objectives:
1.
2.
Experimental contents:
1. Write a program using fork(),wait() etc..
program code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
int main() {
pid_t pid;
if (pid < 0) {
perror("Fork failed");
exit(1);
} else if (pid == 0) {
printf("Child Process: PID = %d, Parent PID = %d\n", getpid(), getppid());
sleep(2);
printf("Child Process terminating...\n");
} else {
printf("Parent Process: PID = %d, Child PID = %d\n", getpid(), pid);
wait(NULL); // Wait for child process to finish
printf("Parent Process resuming after child termination.\n");
}
return 0;
}
screenshot
2. Write a program using pthread_create(), pthread_join() etc..
program code: and
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
int main() {
pthread_t thread1, thread2;
int id1 = 1, id2 = 2;
pthread_join(thread1, NULL);
pthread_join(thread2, NULL);
screenshot: