0% found this document useful (0 votes)
5 views6 pages

Experiment 2

The document provides an overview of system calls, which serve as an interface between processes and the operating system, detailing their necessity and various methods. Key methods discussed include fork(), getpid(), getppid(), exec(), and exit(), each illustrated with examples. The document emphasizes the role of system calls in file management, memory management, process control, and hardware access.

Uploaded by

pritish5903
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views6 pages

Experiment 2

The document provides an overview of system calls, which serve as an interface between processes and the operating system, detailing their necessity and various methods. Key methods discussed include fork(), getpid(), getppid(), exec(), and exit(), each illustrated with examples. The document emphasizes the role of system calls in file management, memory management, process control, and hardware access.

Uploaded by

pritish5903
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

EXPERIMENT 2

Aim : System Call and it’s methods.

System Call :

A system call is a mechanism that provides the interface between a process and Operating system. It
is a programming method in which a computer program requests any service from the Kernel to
Operating System.

Example-

To copy file contents from one file to another file.

Why System call is required ?

System call performs following activities:

1. To read and write data into the file.

2. To delete and maintain file management system.

3. To manage memory.

4. To establish network connection.

5. To access hardware devices.

6. To create and terminate process.

System Call Methods :

1. fork() – This method is used to create a child process within a parent process.

Example :-

# include<stdio.h>

#include<sys/types.h>

#include<unistd.h>

Int main()

Fork();

Printf(“/n Hello….. system call”);

Return 0;
EXAMPLE 2

int main()

fork();

fork();

fork();

printf("/n hello..System call");

return 0;

EXAMPLE 3

int main()

int i , n=5;

for(i=1 ;i<=n; i++){

fork();

printf("/n hello..CSE");

}
return 0;

2. getpaid()

This method is used to get the id of the child process

EXAMPLE

#include<iostream>

#include<sys/types.h>

#include<unistd.h>

Int main()

int n=fork();

if(n==0)

cout<<”\n child process id=”<<getpid();

else

cout<<”\n process is not going on”;

return 0;

}
3) getppid()- the method is used to get id of the parent process.”

EXAMPLE

#include<iostream>

#include<sys/typrs.h>

#include<unistal.h>

Int main()

int n=fork();

if(n==0)

Cout<<”\n child process ID=”<<getpid();

Cout<<”\n parent process ID=”<<getpaid();

return 0;

4. exec() - This method is used to execute all the executable files within the process.

5. execl() – This methos is used to list out all the executable files from root as well as system
Kernel.

Example :

# include<stdio.h>

#include<sys/types.h>

#include<unistd.h>

Int main()

Char *path=”/bin/ls”;

Char *a=”lh”;

Char *b=”/home”;

Execl(path,path,a,ab,NULL);

Return 0;

}
6. exit():-

This function is used to terminate any process from (active).

EXAMPLE 1

# include<stdio.h>

#include<sys/types.h>

#include<unistd.h>

Int main()

Int i;

For (i=1;i<=10;i++)

If (i>=5)

Exit(0)

printf(“\n %d”,i);

return 0;

EXAMPLE 2

Int n=fork();

If(n==0)

fork();

fork();

printf(“\n Hello CSE” );

}else

exit(0);

return 0;
}

You might also like