0% found this document useful (0 votes)
14 views5 pages

Eishal OS

The document discusses C programs demonstrating the fork(), close(), exec(), and exit() system calls. It includes the source code for programs that create a child process, close a file handle, execute another program, and exit a process respectively.

Uploaded by

Eishal Zahra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views5 pages

Eishal OS

The document discusses C programs demonstrating the fork(), close(), exec(), and exit() system calls. It includes the source code for programs that create a child process, close a file handle, execute another program, and exit a process respectively.

Uploaded by

Eishal Zahra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

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

You might also like