CS303- Lab3 (3)
CS303- Lab3 (3)
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)
c) Write a program C that creates 10 children. Each child will print its pid 10 times. The parent waits
for all the children.