By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,470 Members | 994 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,470 IT Pros & Developers. It's quick & easy.

system call and library call

P: n/a
hello,
what is difference between system call and library function
call? Does library function call can have context switch to kernel
mode?
regards,
rahul

Nov 15 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
> what is difference between system call and library function
call?
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
Nov 15 '05 #2

P: n/a
ra*******@gmail.com writes:
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.

--
Philippe Amarenco, aka Phix
epita 2007 - LSE - EpX
"if new true friend not protected for explicit private union, break
case and try using this." -- Nathan Myers, longest c++ sentence.
Nov 15 '05 #3

P: n/a
ra*******@gmail.com 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.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
But I do believe in this.
Nov 15 '05 #4

P: n/a
go****@hammy.burditt.org (Gordon Burditt) writes:
what is difference between system call and library function
call?


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.


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.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #5

P: n/a
ra*******@gmail.com wrote:
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
----
Learn to program using Linux assembly language
http://www.cafeshops.com/bartlettpublish.8640017
Nov 15 '05 #6

P: n/a
Jonathan Bartlett <jo*****@eskimo.com> writes:
ra*******@gmail.com wrote:
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.


Is

http://www.cs.princeton.edu/courses/...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 !!!
Nov 15 '05 #7

P: n/a
the current version of your book (as found by google)?


The official site is http://savannah.nongnu.org/projects/pgubook/

However, the online PDF one is slightly older than the print version.
The XML files are actually slightly newer (available in Savannah's CVS),
but I haven't built a PDF of them, and probably won't until I release a
new edition.

Jon
----
Learn to program using Linux assembly language
http://www.cafeshops.com/bartlettpublish.8640017
Nov 15 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.