Professional Documents
Culture Documents
Operating Systems Lab (CSE2005) Experiment - 8 System Call VS Function Call
Operating Systems Lab (CSE2005) Experiment - 8 System Call VS Function Call
Aim:
To Write a Program to Compare System Call and Function Call.
Procedure:
1. Open a C/C++ Compiler.
2. Write the required program and code for the algorithm.
3. Fill in values for all the parameters.
4. Observe and Verify the Outputs.
5. Compare the Values of Average Time for System Call and Average Time for Function
Call.
Code:
#include <sys/time.h>
#include <unistd.h>
#include <assert.h>
#include<stdio.h>
int ret10()
{
return(10);
}
void main()
{
int i,j,res;
long iterations=1000000;
float avgTimeSysCall, avgTimeFuncCall;
struct timeval t1, t2;
res=gettimeofday(&t1,NULL);
assert(res==0);
res=gettimeofday(&t2,NULL);
assert(res==0);
avgTimeSysCall = (nanosec(t2) - nanosec(t1))/(iterations*1.0);
res=gettimeofday(&t1,NULL); assert(res==0);
res=gettimeofday(&t2,NULL);
assert(res==0);
avgTimeFuncCall = (nanosec(t2) - nanosec(t1))/(iterations*1.0);
printf("Average time for System call getpid : %f\n",avgTimeSysCall);
printf("Average time for Function call : %f\n",avgTimeFuncCall);
}
Output:
Results:
Thus, We have successfully written a program to find the Average time for System Call and
Average time for Function Call. It can be observed that for the Average time for Function Call
is less than the Average time for System Call in the above case.
END