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

OSC LAB MANUAL

The document outlines a program that demonstrates process management in a Unix-like operating system using system calls. It explains the creation and handling of processes using fork() and getpid(), highlighting the differences between parent and child processes. The program includes code that illustrates obtaining process IDs and managing process execution.

Uploaded by

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

OSC LAB MANUAL

The document outlines a program that demonstrates process management in a Unix-like operating system using system calls. It explains the creation and handling of processes using fork() and getpid(), highlighting the differences between parent and child processes. The program includes code that illustrates obtaining process IDs and managing process execution.

Uploaded by

mriga jain
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

PROGRAM PAGE NO.

1 Process System Calls


2 IO System Calls
3 IPC using Pipe Processing
4 First Come First Serve Scheduling
5 Shortest job first Scheduling
6 Priority Scheduling
7 Round Robin Scheduling 8.
8 Simulate Page Replacement Algorithms FIFO
9 Simulate Page Replacement Algorithms LRU
10 Simulate Page Replacement Algorithms OPTIMAL
INDEX
Program 1

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:

1. Obtaining the current process ID.


2. Creating a new process using fork().
3. Differentiating between parent and child processes.

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:

 getpid() provides the ID of the current process.


 getppid() provides the ID of the parent process.

Parent vs. Child Process:

 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

// Get and print the current process ID


pid = getpid();
printf("Parent Process ID: %d\n", pid);

// Create a child process


pid_t child_pid = fork();

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);
}

// End of the program


return 0;
}

You might also like