alp-ch08-linux-system-calls

alp-ch08-linux-system-calls - 10 0430 Ch08 10:33 AM Page...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Linux System Calls 8 S OFAR , WE VE PRESENTED A VARIETY OF FUNCTIONS that your program can invoke to perform system-related functions, such as parsing command-line options, manipu- lating processes, and mapping memory. If you look under the hood, you’ll find that these functions fall into two categories, based on how they are implemented. n A library function is an ordinary function that resides in a library external to your program. Most of the library functions we’ve presented so far are in the standard C library, libc . For example, getopt_long and mkstemp are functions provided in the C library. A call to a library function is just like any other function call.The arguments are placed in processor registers or onto the stack, and execution is transferred to the start of the function’s code, which typically resides in a loaded shared library. n A system call is implemented in the Linux kernel.When a program makes a system call, the arguments are packaged up and handed to the kernel, which takes over execution of the program until the call completes.A system call isn’t an ordinary function call, and a special procedure is required to transfer control to the kernel. However, the GNU C library (the implementation of the standard C library provided with GNU/Linux systems) wraps Linux system calls with functions so that you can call them easily. Low-level I/O functions such as open and read are examples of system calls on Linux.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
168 Chapter 8 Linux System Calls The set of Linux system calls forms the most basic interface between programs and the Linux kernel. Each call presents a basic operation or capability. Some system calls are very powerful and can exert great influence on the system. For instance, some system calls enable you to shut down the Linux system or to allocate system resources and prevent other users from accessing them.These calls have the restriction that only processes running with superuser privilege (programs run by the root account) can invoke them.These calls fail if invoked by a nonsuperuser process. Note that a library function may invoke one or more other library functions or system calls as part of its implementation. Linux currently provides about 200 different system calls.A listing of system calls for your version of the Linux kernel is in /usr/include/asm/unistd.h . Some of these are for internal use by the system, and others are used only in implementing special- ized library functions. In this chapter, we’ll present a selection of system calls that are likely to be the most useful to application and system programmers. Most of these system calls are declared in <unistd.h> . 8.1 Using strace Before we start discussing system calls, it will be useful to present a command with which you can learn about and debug system calls.The strace command traces the execution of another program, listing any system calls the program makes and any sig- nals it receives. To watch the system calls and signals in a program, simply invoke
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 22

alp-ch08-linux-system-calls - 10 0430 Ch08 10:33 AM Page...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online