library function vs system calls

S

sophia.agnes

Dear all,

I was going through peter van der linden's book expert C programming
there i found the following:-

Library call
------------

*call to a routine in a library
*linked with user program
*executes in user address space
*counts as a part of user time
*has the lower head overhead of procedure call.

system call
-----------
* call to the kernel for a service
* is an entry point to the OS
* executes in the kernel address space
* has high overhead switch to kernel and back

then the author says that , remember many routines in the C library do
their work by making system calls and system() call is
actually a library call.

then how valid is the above explanation on the differences between
library call versus system call ?

why system() call is treated as a library call ?
 
W

Willem

(e-mail address removed) wrote:
) why system() call is treated as a library call ?

The library call 'system()' and the term 'system call' just happen to have
the word 'system' in them. That doesn't mean they are related in any way.

You can write 'kernel call' instead of 'system call', but it wouldn't
make sense to rename the system() function to kernel().


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
 
S

santosh

Dear all,

I was going through peter van der linden's book expert C programming
there i found the following:-

Library call
------------

*call to a routine in a library
*linked with user program
*executes in user address space
*counts as a part of user time
*has the lower head overhead of procedure call.

system call
-----------
* call to the kernel for a service
* is an entry point to the OS
* executes in the kernel address space
* has high overhead switch to kernel and back

then the author says that , remember many routines in the C library do
their work by making system calls and system() call is
actually a library call.

then how valid is the above explanation on the differences between
library call versus system call ?

why system() call is treated as a library call ?

No. He simply means that many library calls like printf() end up calling
one or more system level routines to do their job. This is because
modern operating systems forbid user level programs from interfacing
hardware directly. Usually they must use the API provided by the OS to
do this, as well as many other things.

For example a printf() call might do a lot work like scanning the format
string and converting the corresponding arguments and building the
final output string without a single call to the system, but finally,
it is unable to actually write to a system device like the display or a
file on the hard disk because the OS forbids such interactions with the
hardware to stop programs from running wild on a multitasking system.
Therefore to output the final string it will typically call a system
level routine like write() on UNIX or WriteFile() under Windows.

Many library functions like those in string.h and many in math.h do all
their work without calling system but functions that need to do I/O or
change system settings or communicate with other processes need to go
through the system.

Under some modern architectures, the "system call" has been optimised to
be much faster than what it was before. Also some operating systems run
under a single privilege level only, and so, under such systems
a "system call" may be no more slower than an ordinary function call.

These details are all very much dependent on the exact configuration of
your hardware and system level software. Please ask in a operating
system group like <for more details.

For a Standard C program, a "system call" does not exist. A POSIX
program can use the "syscall()" macro do call system entry points. Also
note that POSIX calls like write() and read() are most often
implemented as ordinary library calls that, under UNIX systems,
actually call a identically named system call. Thus the POSIX read()
function may itself call the 'read' system call to do it's work.
Because POSIX was standardised based on the then existing UNIX
interface, many of it's routines are simply wrappers to correspondingly
named UNIX system calls.

<http://en.wikipedia.org/wiki/System_call>
<http://www.unix.org/single_unix_specification/>
<http://www.developertutorials.com/tutorials/linux/linux-command-line-utility-050430/page8.html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top