0% found this document useful (0 votes)
0 views

CS303- Lab3 (3)

The document provides an overview of key system calls used in operating systems, particularly focusing on process management functions such as Fork(), Wait(), Getpid(), Getppid(), and Exec(). It also includes exercises for students to implement process trees and create C programs that handle command-line arguments to execute commands in parallel and sequentially, as well as a program that creates multiple child processes. The exercises aim to enhance understanding of process creation and management in C programming.

Uploaded by

mehdi bouzouaya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

CS303- Lab3 (3)

The document provides an overview of key system calls used in operating systems, particularly focusing on process management functions such as Fork(), Wait(), Getpid(), Getppid(), and Exec(). It also includes exercises for students to implement process trees and create C programs that handle command-line arguments to execute commands in parallel and sequentially, as well as a program that creates multiple child processes. The exercises aim to enhance understanding of process creation and management in C programming.

Uploaded by

mehdi bouzouaya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

CS303 Operating Systems

Lab: System Calls (2)

Main system calls we will be using are summarized in the following table:

Function Description
#include <sys/types.h> Clone the current process. Typically used to
#include <unistd.h> create a new instance of the current execution
Fork() environment; to create a new process running
If (fork() == 0) : this is the child a different program.
If (fork() > 0) : this is the parent
If (fork() < 0) : child process not created
#include <sys/wait.h> Wait termination of a process
Wait()
Waitpid()
#include <unistd.h>
Getpid() Get process identifier
Getppid() Get parent process identifier
#include <unistd.h> Replaces the current process with a new
Exec*() process, loaded from an executable file
Exercises
a) Write a C program that implements this process tree:

b) Write two C programs that receive commands as command-line arguments (passed commands are
without arguments) and create a child for each command. Example: $ ./prog ps ls who (parent
process executes the last command)

• Scenario 1: Parallel Execution ➔ ps & ls & who

• Scenario 2: Sequential Execution ➔ ps ; ls ; who

c) Write a program C that creates 10 children. Each child will print its pid 10 times. The parent waits
for all the children.

You might also like