OS Lab 06

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Operating System

CSL 320

Lab Journal: 06

Name: Muhammad Ali Khan


Class: BCE-5A
Enrollment no: 01-132172-007
Lab No. 06

System Calls
Software used:

 VMware
 Ubuntu
 VI editor
Introduction:

In computing, a system call is the programmatic way in which a computer program requests a
service from the kernel of the operating system it is executed on. A system call is a way for
programs to interact with the operating system. A computer program makes a system call when
it makes a request to the operating system’s kernel. System call provides the services of the
operating system to the user programs via Application Program Interface (API). It provides an
interface between a process and operating system to allow user-level processes to request services
of the operating system
Services Provided by System Calls:
1. Process creation and management
2. Main memory management
3. File Access, Directory and File system management
4. Device handling(I/O)
5. Protection
6. Networking, etc.

Task 01: Run the Example 1 twice and thrice and observe the results.
Code:
#include<stdio.h>
#include<sys/types.h>
int main()
{
pid_t pid,ppid;
pid = getpid();
ppid = getppid();
printf("Process ID is %d\n",pid);
printf("Parent Process ID is %d\n",pid);
return 0;
}
Output:

Task 02: Show the output of ps command running on your terminal.

Task 03:

 Running program process ID.

• Creates child process using fork


display Child PID and parent PID in child process.
display Child PID and parent PID in parent process
Code:

#include<stdio.h>
#include<sys/types.h> }
#include <stdlib.h> else {
#include <unistd.h> pid2 = fork();
int main() if (pid2 == 0) {
{ printf("child[3] --> pid = %d and
int pid, pid1, pid2; ppid = %d\n", getpid(), getppid());
pid = fork() ; }
if (pid == 0) { else {
printf("\nchild[1] --> pid = %d and printf("parent --> pid = %d\n",
ppid = %d\n", getpid(), getppid()); getpid());
} }
else { }
pid1 = fork(); }
if (pid1 == 0) { return 0;
printf("child[2] --> pid = %d and }
ppid = %d\n", getpid(), getppid());

Output:

Task: 04

Observe the Output of this code:

 With MAX_COUNT = 5
 With MAX_COUNT = 20
 With MAX_COUNT = 200
Code:

#include<stdio.h>
#include<sys/types.h> void ChildProcess(void);
#include<stdlib.h> void ParentProcess(void);
#include<unistd.h> void main(void)
#define MAX_COUNT 5 {
pid_t pid; printf( " this line is from child, value =
pid = fork(); %d\n", i);
if(pid == 0) printf( " ***Child Process is done
ChildProcess(); ***\n");
else }}
ParentProcess(); void ParentProcess(void)
} {
void ChildProcess(void) int i;
{ for(i = 1; i <= MAX_COUNT; i++)
int i; {
for(i = 1; i <= MAX_COUNT; i++) printf( " this line is from Parent , value =
{ %d\n", i);
printf( " *** PArent Process is done
***\n");
}
Output:
Conclusion:

In this lab we have study about the system call and its services. We have learned about the fork (),
wait () and exit () function in this lab. Also, we have executed different process using the above
command to run the program. We performed all the tasks given by the teacher.

You might also like