Page | 50 System calls are expensive. While a procedure call can usually be performed
in a few machine instructions, a system call requires
the computer to save its state, let the operating
system take control of the CPU, have the operating
system perform some function, have the operating
system save its state, and then have the operating system give control of the CPU back to you. Usually when an error occurs in a system or library calla special
return value comes back, and a global variable "
errno" is set to say what the error is. For example, suppose you try to open a file
that does not exist include < stdio.h > include < errno.h > main)
{ int i
FILE ff fopen("
huangj/nonexist", riff NULL) { printf("f = null. errno = %d\n", errno); perror("f1");
}
}
Share with your friends: