08-22-04 11:08 PM
Prakash Prabhu wrote:
> Hi,
>
> What are the differences between a system call and library function
> call except for the fact that the former is executed in kernel mode
> while the latter in user mode ? ( does this by itself have its own
> implications ? )
>
> Thanks,
> Prakash
I presume you mean library calls which are analogous to
system calls. For example, the system calls
open(), close(), read(), write(), lseek(), etc.
can be used directly, but there are stdio library
calls (fopen(), fclose(), etc.) which seem to
do the same thing.
When using the low-level system calls, you often
have to do a lot of work to use them most efficiently.
For example, the fread() and fwrite() functions (library
calls), buffer the I/O at what is probably the optimal
size for the given O/S. Fwrite() will only issue
a "write()" call when it's buffer is full,
thus minimizing unnecessary write() calls.
(There are ways of overriding this, e.g. fflush()).
These particular library calls are saving you the
effort of having to re-invent buffered I/O all by
yourself every time you write a program which needs
I/O. Use of the library calls is thus, in the long
run, more productive and also allows your code
to be more portable to other platforms because the
compilers on those other platforms will have the
same standard libraries and will hide the O/S
specific differences from you, for the most
part.
--
"It is impossible to make anything foolproof
because fools are so ingenious"
- A. Bloch
[ Post a follow-up to this message ]
|