OSC LAB MANUAL
OSC LAB MANUAL
Process System Calls - In operating systems, a system call is a way for programs to interact with
the operating system's kernel. When a program needs to perform an operation that requires higher
privileges or needs to access hardware resources, it uses a system call.
The goal of the program is to illustrate how process management works in a Unix-like
operating system using system calls. The following program demonstrates how to create and
handle processes using fork() and getpid() system calls. Specifically, it demonstrates:
Process Creation: fork() creates a new process, which is a copy of the parent process. The
child process starts executing right after the fork() call, but with a new process ID.
Process IDs:
After fork(), both the parent and child processes execute independently. They can be
distinguished using the value returned by fork().
Observations
Output Behaviour: The output will show different process IDs for the parent and
child processes. You might observe that the child process has a different PID and its
parent’s PID is the same as the parent process’s PID.
System Calls: This program helps in understanding fundamental system calls related
to process management, which is crucial for OS development and understanding
process control in Unix-like systems.
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
int main() {
pid_t pid; // Declare variable for process ID
if (child_pid < 0) {
// Fork failed
perror("fork");
return 1;
} else if (child_pid == 0) {
// This block is executed by the child process
printf("Child Process ID: %d\n", getpid());
printf("Parent Process ID (from child): %d\n", getppid());
} else {
// This block is executed by the parent process
printf("In Parent Process: Child Process ID: %d\n", child_pid);
}