ASSIGNMENT 01
Program --------------------------------------------------------------------------------- BSCS
Semester --------------------------------------------------------------------------------- 6th
Session ----------------------------------------------------------------------------------- 2021-2025
Subject --------------------------------------------------------------------------------- Operating System
Submitted To ------------------------------------------------------------------------- Ms. Iqra Mehmood
Submitted By ----------------------------------------------------------------------- Eishal Zahra
Roll No. -------------------------------------------------------------------------------- B-CS-21122
Date ----------------------------------------------------------------------------------- 25th March 24
DEPARTMENT OF COMPUTER SCIENCE & IT
UNIVERSITY OF JHANG
Fork() System call program in C Language:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void create_process() {
pid_t pid = fork();
if (pid < 0) {
printf("Error creating child process.\n");
exit(1);
else if (pid == 0) {
// Child process
printf("Hello from the child process!\n");
// Add your code here for the child process
exit(0);
else {
// Parent process
printf("Hello from the parent process!\n");
// Add your code here for the parent process
wait(NULL);
int main()
create_process();
return 0;
Close() System Call Program in C language:
#include <stdio.h>
#include <stdlib.h>
void close_handle(FILE *file) {
if (file != NULL) {
fclose(file);
printf("Handle closed successfully.\n");
else {
printf("Invalid handle.\n");
int main() {
// Example usage
FILE *file = fopen("example.txt", "r");
close_handle(file);
return 0;
Exec() System Call Program in C language:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void exec_process() {
char *args[] = {"ls", "-l", NULL};
execvp(args[0], args);
printf("Exec failed!\n");
exit(1);
}
int main() {
// Example usage
exec_process();
return 0;
Exit() System Call Pogram in C language:
#include <stdio.h>
#include <stdlib.h>
void exit_process()
printf("Exiting the process...\n");
exit(0);
int main() {
// Example usage
exit_process();
return 0;
THE END