Issue
When the below C program is run in a Linux,the execution of which line must trigger invocation of system call, why? What is invocation of system call ?
void main()
{
double x=1;
double y;
double *z;
z=(double *)malloc(sizeof(double)); // line 1
scanf("%f", &y); // line 2
*z=sqrt(y); // line 3
y=y*2.0; // line 4
printf("y=%f, *z=%f\n", y, *z); // line 5
y=y/x; // line 6
printf("y=%f",y); // line 7
}
Solution
A call to malloc
invokes a system call because the operating system manages the memory.
Calls to scanf
and printf
invoke system calls because the operating system manages i/o operations.
Invocation of a system call is a call for an operating system service.
Answered By - gmoshkin