C system call and library call

This is a discussion on C system call and library call within the C Programming forums, part of the General Programming Boards category; Hi people, I am new to this board. I just learn C programming for 2 months. Can anyone explain clearly ...

  1. #1
    Coconut
    Guest

    C system call and library call

    Hi people,
    I am new to this board. I just learn C programming for 2 months.
    Can anyone explain clearly about what exactly difference between system call and library call? I just know that
    system call is called from OS, and library call is from supported
    compiler, but I really dont know their different functions and how each call do within a program?
    Your help would be appreciated.
    Coconut

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Short answer:
    System calls are a part of the operating system and library calls are a part of a language.

    Long answer:
    A system call is a call to the kernel for something and acts as an entry point into the operating system. A system call executes in kernel address space and counts as part of the system time. System calls have a high overhead because of the switch to kernel and back, they are specific to each operating system and generally are not portable.

    A library call is a call to a routine in a library, such as printf, and is linked with the program. It executes in the user address space that is passed out by the operating system for user programs and has a much lower overhead than a system call. Library calls can be bundled up with a program so that they are portable.

    >but I really dont know their different functions and how each call do within a program
    system(), printf(), malloc(), exit() are all library calls. fork, chdir dir, cd, are all system calls. Inside your program you will be making library calls, you can figure out how to use them by reading either the man pages or documentation that should come with a library.

    I hope this helps.

    -Prelude
    My best code is written with the delete key.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Both are function calls. A "library call" as you put it, means you link your program to a library of functions, and you are using one of those functions. The "system call" is where you pass information off to the operating system and it does some other task.

    Example: "system("format c:");" passes the command line "format c:" off to your operating system. Basicly it "shells out" to the operating system, preforms a task, and then returns to the program when it's done.

    [edit]A day late, and a dollar short...[/edit]

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Coconut
    Guest
    Thanks a lot. You are great!
    Can you explain a little bit more about what is "entry point" of
    kernel? and is that system call and library call are invoked at
    compiler time or runtime? Also you mean "system time" is
    CPU time?
    Again, thank you
    Coconut

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Can you explain a little bit more about what is "entry point" of kernel?
    Assuming you use Windows, say you type in

    DIR C:\SOMEDIR

    This sends a message to the operating system requesting that it perform a task, in this case open the directory C:\SOMEDIR and spill the contents to the screen. That is a system call, to the user it doesn't get any easier.

    >and is that system call and library call are invoked at compiler time or runtime?
    I could get into the details of the call stack, but that isn't quite relevant to your question. Both are made at run-time. However, system calls are not limited to the execution time of your program, they can be made any time the computer is running.

    >Also you mean "system time" is CPU time?
    I mean system time as the time when the computer is running.

    -Prelude
    My best code is written with the delete key.

  6. #6
    Nick
    Guest
    It depends on what your talking about. For
    some this is a system call
    system("dir") and really this all depends on context.

    For linux, the system calls are a little different than c
    functions.
    http://quaff.port5.com/syscall_list.html
    This shows a good sampling of what system calls do.

    All of the system calls have c wrapper functions so you
    can call them like normal c functions.

    Another thing you can do is use something like strace to get all
    of the system calls done for implementing a simple
    command such as ls or cat.

  7. #7
    Visionary Philosopher Sayeh's Avatar
    Join Date
    Aug 2002
    Posts
    212
    Actually, aside from all the "high-level verbage", the difference between the two is simple:

    A system call is a jump to a procedure/function that is listed in the O/S' trap table. This is also called a 'trap call', because it is essentially handled by the exception handler.

    A library call, on the other hand, is a jump to a procedure/function that resides within a linkable library of precompiled code. The specific addresses are resolved by the linker at compile time.

    ---

    All calls are executed after compilation, during execution time. Using the term 'runtime' is a misnomer, because 'runtime' is actually a reference to execution of an interpreted language.
    It is not the spoon that bends, it is you who bends around the spoon.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stack issues when calling a COM library
    By notnot in forum C Programming
    Replies: 3
    Last Post: 06-01-2009, 02:12 AM
  2. Newbie Help. I can't use pow and call the math library.
    By BSmith4740 in forum C Programming
    Replies: 10
    Last Post: 06-10-2008, 07:22 PM
  3. Makefile for a library
    By sirmoreno in forum Linux Programming
    Replies: 5
    Last Post: 06-04-2006, 04:52 AM
  4. exe files in -c- language
    By enjoy in forum C Programming
    Replies: 6
    Last Post: 05-18-2004, 04:36 PM
  5. Can c legacy program call c++ library?
    By happylee in forum C Programming
    Replies: 2
    Last Post: 02-20-2002, 11:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21