Experiment 2 Hassan
Experiment 2 Hassan
EXPERIMENT-2
Objective:To understand and execute different UNIX system calls related to:
1. Process Management
2. File Management
3. Input/Output Operations
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include <stdlib.h>
int main() {
pid_t pid = fork(); // Create child process
if (pid == 0) {
// Child process
printf("Child process: PID = %d\n", getpid());
exit(0); // Child exits
} else {
// Parent process
wait(NULL); // Wait for child to finish
printf("Parent process: PID = %d, child completed.\n",
getpid());
}
return 0;
}
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
int main() {
int fd = open("sample.txt", O_CREAT | O_WRONLY, 0644);
if (fd < 0) {
perror("File creation failed");
return 1;
}
return 0;
}
#include <stdio.h>
#include <unistd.h>
int main() {
char buffer[100];
int n;
return 0;
}
Result:
Successfully executed various UNIX system calls: