473,405 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

system call and library call

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
7 6927
> 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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
3
by: faktujaa | last post by:
Hi All, A small confusion. I have defined a connection class that has System.Data.IDbConnection as a member variable and implements IDisposable interface. I have implemented Dispose method to call...
5
by: markus | last post by:
Hi, I have a question that deals with the standard c library VS (Unix) system calls. The question is: which header files (and functions) are part of the C library and which header files (and...
8
by: bob | last post by:
Which is faster - a call to a system function or a call to a library function?
6
by: leoman730 | last post by:
This is one of the interview question this morning, hope someone can help out with this. Thanks. What is the different between System call and library call?
21
by: omkar pangarkar | last post by:
Hi all, I have two simple hello world programs one using printf() and other using write() --prog 1-- #include<stdio.h> #include<stdlib.h> int main() { printf("Hello"); /* up to here...
1
by: sophia.agnes | last post by:
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...
16
by: Paul Schwann | last post by:
Hi group, I am relatively new to C# (although I have a lot of programming excperience in other languages like Java and C). Currently I am searching for a solution to this problem: Suppose you...
0
ashitpro
by: ashitpro | last post by:
Writing System Call Wrappers in User Space. Recently I saw a post in Linux/Unix section to know the user who deleted the file in linux. Currently there is nothing in linux which could achieve...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.