Os Prac 2
Os Prac 2
Experiment – 2
#include <stdio.h>
#include <unistd.h>
<sys/wait.h>
int main() {
if (pid < 0) {
// Fork failed
perror("Fork failed");
return 1;
// Child process
printf("Child Process:\n");
} else {
// Parent process
printf("Parent Process:\n");
return 0;
Output
Child Process:
Parent Process:
#include <unistd.h>
int main() {
int fd;
if (fd < 0) {
return 1;
close(fd);
fd = open("sample.txt", O_RDONLY);
if (fd < 0) {
return 1;
close(fd);
return 0;
Output :
File content:
char buffer[100];
int n;
return 0;
Output (Example):
Enter some text: Hello System Calls!