system call and library call

R

rahul8143

hello,
what is difference between system call and library function
call? Does library function call can have context switch to kernel
mode?
regards,
rahul
 
G

Gordon Burditt

what is difference between system call and library function

Unless you are talking about a specific implementation, the spelling
of the name. What is a system call on one machine may be a library
function on another, and it can easily change between versions (e.g.
when a legacy system call is now implemented as a library function
that calls the new system call, re-arranging the arguments and
results so it works like the old one did).
Does library function call can have context switch to kernel
mode?

Yes, as a library call often calls system calls (at least conditionally)
to do its work. For example, if you call putc() a lot, at least
some of them will call something in the kernel to actually get the
I/O done, at least on UNIX-like systems where there is a kernel.

Gordon L. Burditt
 
P

Philippe Amarenco

hello,
what is difference between system call and library function
call? Does library function call can have context switch to kernel
mode?

a library call is a normal function, with the "call" assembly
instruction.
a system call is kernel done with a different instruction like
software interrupts ("int" asm instruction on x86) or dedicated
instruction ("sysenter" on x86, "sc" on ppc, ...). whatever the way to
do it, the call change the privilege level from "user" to "kernel" and
a function priorly defined by the kernel is called.
 
J

Jonathan Bartlett

hello,
what is difference between system call and library function
call? Does library function call can have context switch to kernel
mode?

To learn more of the differences on Linux, you should check out my book,
Programming from the Ground Up. But basically, a library call is a
"normal" function call, while a system call goes through the kernel.
Library functions do not go to kernel mode for the call instruction, but
often do so within the actual library function. In fact, a single
library function may make zero, one, or several system calls and do
context switches to kernel mode.

Jon
 
S

SM Ryan

(e-mail address removed) wrote:
# hello,
# what is difference between system call and library function
# call? Does library function call can have context switch to kernel
# mode?

Typically a system call is a library function that does the minimal
necessary overhead to send a request to the kernel and then decode
the response from the kernel. What requests a kernel accepts depend
on the system. Some things that are system calls in unix become
library functions on non-unix posix implementations.

On a system with preemptive process switches (like unix), going to
the next instruction can involve a context switch. On a system
where context switches to relevant to the average program (like Mac
System 7), the library documentation should tell what can cause
switches.
 
K

Keith Thompson

Unless you are talking about a specific implementation, the spelling
of the name. What is a system call on one machine may be a library
function on another, and it can easily change between versions (e.g.
when a legacy system call is now implemented as a library function
that calls the new system call, re-arranging the arguments and
results so it works like the old one did).


Yes, as a library call often calls system calls (at least conditionally)
to do its work. For example, if you call putc() a lot, at least
some of them will call something in the kernel to actually get the
I/O done, at least on UNIX-like systems where there is a kernel.

Both the question and the answer are off-topic in comp.lang.c. I just
noticed the cross-post to comp.unix.programmer, where it is topical;
followups redirected.

Many library calls do not require a context switch to kernel mode;
consider strlen(), for example.

For the most part, even on systems where the distinction is
meaningful, there's seldom any reason to care whether you're invoking
a system call or not.
 
D

Dragan Cvetkovic

Jonathan Bartlett said:
To learn more of the differences on Linux, you should check out my book,
Programming from the Ground Up. But basically, a library call is a
"normal" function call, while a system call goes through the
kernel. Library functions do not go to kernel mode for the call
instruction, but often do so within the actual library function. In fact,
a single library function may make zero, one, or several system calls and
do context switches to kernel mode.

Is

http://www.cs.princeton.edu/courses...eading/ProgrammingGroundUp-1-0-lettersize.pdf

the current version of your book (as found by google)?

TIA, Dragan

--
Dragan Cvetkovic,

To be or not to be is true. G. Boole No it isn't. L. E. J. Brouwer

!!! Sender/From address is bogus. Use reply-to one !!!
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top