Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > system call and library call

Reply
Thread Tools

system call and library call

 
 
rahul8143@gmail.com
Guest
Posts: n/a
 
      08-22-2005
hello,
what is difference between system call and library function
call? Does library function call can have context switch to kernel
mode?
regards,
rahul

 
Reply With Quote
 
 
 
 
Gordon Burditt
Guest
Posts: n/a
 
      08-22-2005
> 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
 
Reply With Quote
 
 
 
 
Philippe Amarenco
Guest
Posts: n/a
 
      08-22-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) 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.
 
Reply With Quote
 
Jonathan Bartlett
Guest
Posts: n/a
 
      08-22-2005
(E-Mail Removed) 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
 
Reply With Quote
 
SM Ryan
Guest
Posts: n/a
 
      08-22-2005
(E-Mail 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.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
But I do believe in this.
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      08-22-2005
(E-Mail Removed) (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) (E-Mail Removed) <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.
 
Reply With Quote
 
Dragan Cvetkovic
Guest
Posts: n/a
 
      08-22-2005
Jonathan Bartlett <(E-Mail Removed)> writes:

> (E-Mail Removed) 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 !!!
 
Reply With Quote
 
Jonathan Bartlett
Guest
Posts: n/a
 
      08-23-2005

> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
static library and dynamic library Even C Programming 6 10-20-2007 04:05 PM
System call and library call leoman730 C++ 6 05-06-2007 12:37 AM
System.Security.SecurityException: Error de solicitud de permiso de tipo System.Net.WebPermission, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089. Luis Esteban Valencia ASP .Net 0 07-14-2005 01:43 PM
Re: Difference between Web Control Library and Class Library Alan Ferrandiz [MCT] ASP .Net 0 09-11-2004 01:51 PM
Re: Difference between Web Control Library and Class Library Mythran ASP .Net 0 08-24-2004 05:53 PM



Advertisments