Find the answer to your Linux question:
Results 1 to 6 of 6
In Linux, 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, ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2011
    Posts
    5

    how do I know what system calls are invoked by a specific library call


    In Linux, 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.

    My question is how do I know what system calls are invoked by a specific library to fulfill the library function?

    For example, fgets() is a shared library function. What system calls are invoked by fgets() to really do its job? What is the implementation detail for the library?

    Your response will be appreciated.

  2. #2
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,758
    how do I know what system calls are invoked by a specific library call
    strace. Run the program with prefix strace.

    strace ./a.out
    It show you the system calls used by that binary.
    First they ignore you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -----
    FOSS India Award winning ext3fs Undelete tool www.giis.co.in. Online Linux Terminal http://www.webminal.org

  3. #3
    Just Joined!
    Join Date
    Mar 2011
    Posts
    5
    Quote Originally Posted by Lakshmipathi View Post
    strace. Run the program with prefix strace.


    It show you the system calls used by that binary.
    I know if I use "ltrace " and "strace" as a prefix, I will get all the library calls and system calls used by the executables. Since I will have a list of library calls and a list of system calls used, how do I know which system calls are invoked by a specific library call?

    Thanks.

  4. #4
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,758
    Quote Originally Posted by forrestgump View Post
    I know if I use "ltrace " and "strace" as a prefix, I will get all the library calls and system calls used by the executables. Since I will have a list of library calls and a list of system calls used, how do I know which system calls are invoked by a specific library call?

    Thanks.
    I don't know about group by glibc call options - One option would be create simple programs with specific glibc function call and use strace to debug.
    But ,I think if you go through the strace checking system calls along with its arguments and return types. you can know which glibc call invoked what kind of sys.call.
    First they ignore you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -----
    FOSS India Award winning ext3fs Undelete tool www.giis.co.in. Online Linux Terminal http://www.webminal.org

  5. #5
    Just Joined!
    Join Date
    Mar 2011
    Posts
    5
    Quote Originally Posted by Lakshmipathi View Post
    I don't know about group by glibc call options - One option would be create simple programs with specific glibc function call and use strace to debug.
    But ,I think if you go through the strace checking system calls along with its arguments and return types. you can know which glibc call invoked what kind of sys.call.
    You mean I need to go through the source code of strace to check system calls along with its arguments and return types? or is there a command to use?

    Thanks,

  6. #6
    Linux Enthusiast Bemk's Avatar
    Join Date
    Sep 2008
    Location
    Oosterhout-NB, Netherlands
    Posts
    525
    If you want to know for a specific library function, can't you just make 3 or so tiny programs that run one library call and then exit.
    Then you run those trace things over them and compare the results. The differences will probably be of most interest.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •