system call and library call

Discussion in 'C Programming' started by rahul8143@gmail.com, Aug 22, 2005.

  1. Guest

    hello,
    what is difference between system call and library function
    call? Does library function call can have context switch to kernel
    mode?
    regards,
    rahul
    , Aug 22, 2005
    #1
    1. Advertising

  2. > 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
    Gordon Burditt, Aug 22, 2005
    #2
    1. Advertising

  3. 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.
    Philippe Amarenco, Aug 22, 2005
    #3
  4. 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
    Jonathan Bartlett, Aug 22, 2005
    #4
  5. SM Ryan Guest

    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.
    SM Ryan, Aug 22, 2005
    #5
  6. (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) <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.
    Keith Thompson, Aug 22, 2005
    #6
  7. Jonathan Bartlett <> writes:

    > 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...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 !!!
    Dragan Cvetkovic, Aug 22, 2005
    #7
  8. Jonathan Bartlett, Aug 23, 2005
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mythran
    Replies:
    0
    Views:
    2,401
    Mythran
    Aug 24, 2004
  2. leoman730

    System call and library call

    leoman730, May 3, 2007, in forum: C++
    Replies:
    6
    Views:
    905
    Jim Langston
    May 6, 2007
  3. David Pratt
    Replies:
    0
    Views:
    250
    David Pratt
    Apr 7, 2008
  4. David Pratt
    Replies:
    0
    Views:
    390
    David Pratt
    Apr 7, 2008
  5. Will Lichtenberger
    Replies:
    3
    Views:
    3,195
    dener
    Nov 5, 2008
Loading...

Share This Page