Transcription of The Linux Programmer's Guide - The Linux …
1 The Linux programmer s GuideSven GoldtSven van der MeerScott BurkettMatt WelshVersion continuing mission: to seek out knowledge of C, to explore strange unixcommands, and to boldly code where no one has man page The Linux operating system72 The Linux kernel93 The Linux libc package114 System calls135 The swiss army knife ioctl156 Linux Interprocess .. UNIX Pipes.. Concepts.. Pipes in C.. the Easy Way!.. Operations with Pipes.. on half-duplex pipes:.. Pipes (FIFOs - First In First Out).. Concepts.. a FIFO.. Operations.. Actions on a FIFO.. Infamous SIGPIPE Signal.. V IPC.. Concepts.. Queues.. Memory..627 Sound the internal speaker.. a sound card.
2 698 Character Cell Function in libc.. Output.. Input.. Termcap Library.. a Terminal Description.. at a Terminal Description.. Capabilities.. - Introduction.. Output.. Characters/Lines.. Characters/Lines.. and Lines.. Character.. Input.. Options.. Attributes.. Options.. Window and Lines.. Updating the Terminal.. Video Attributes and Color.. Cursor and Window Coordinates.. Scrolling.. Pads.. Soft-labels.. Miscellaneous.. Low-level Access.. Screen Dump.. Termcap Emulation.. Terminfo Functions.. Debug Function.. Terminfo Capabilities.. Boolean Capabilities.. Numbers.. Strings.. [N]Curses Function Overview..1129 Programming I/O Programming.
3 Programming.. Programming.. Programming..11710 Porting Applications to Introduction.. Signal handling.. Signals under SVR4, BSD, and .. Linux signal options.. Linux .. Signals supported by Linux .. Terminal I/O.. Process information and control.. the/procfilesystem.. Process control under Linux .. Portable conditional compilation.. Additional Comments..124 CONTENTS511 Systemcalls in alphabetical order12512 Abbreviations131 CopyrightThe Linux programmer s Guide isc 1994, 1995 by Sven GoldtSven Goldt, Sachsendamm 47b, 10829 Berlin, Germany< > .Chapter8isc 1994, 1995 by Sven van der Meer< > .Chapter6isc 1995 Scott Burkett< > .Chapter10isc 1994, 1995 Matt Welsh< >.
4 Special thanks goes to John D. Harper< >for proofreadingthis to reproduce this document in whole or in part is subject to the copyright notice remains intact and is you make money with it the authors want a authors are not responsible for any harm that might arise by the use of it. PrefaceThis Guide is far from being first release started at version in September 1994. It concentrated on systemcalls because of lack of manpower and information. Planned are the description oflibrary functions and major kernel changes as well as excursions into important areaslike networking, sound, graphics and asynchronous I/O. Maybe some hints abouthow to build shared libraries and pointers to useful toolkits will later be Guide will only be a success with generous help in the form of information orperhaps even submission of whole chapters.
5 IntroductionOnce upon a time I installed Linux on my PC to learn more about system administra-tion. I tried to install a slip server but it didn t work with shadow and mgetty. I hadto patch sliplogin and it worked until the new Linux releases. No one could tellme what had happened. There was no documentation about changes since the except the kernel change summaries from Russ Nelson, but they didn t helpme very much in solving Linux programmer s Guide is meant to do what the name implies It is to helpLinux programmers understand the peculiarities of Linux . By its nature, this alsomeans that it should be useful when porting programs from other operating systemsto Linux . Therefore, this Guide must describe the system calls and the major kernelchanges which have effects on older programs like serial I/O and Goldt The Linux programmer s Guide6 Chapter 1 The Linux operating systemIn March 1991 Linus Benedict Torvalds bought the multitasking system Minix for his AT386.
6 He used it to develop his own multitasking system which he called Linux . In Septem-ber 1991 he released the first prototype by e-mail to some other Minix users on the internet,thus beginning the Linux project. Many programmers from that point on have supportedLinux. They have added device drivers, developed applications, and aimed for POSIX compliance. Today Linux is very powerful, but what is best is that it s free. Work is beeingdone to port Linux to other 1. THE Linux OPERATING SYSTEMC hapter 2 The Linux kernelThe base of Linux is the kernel. You could replace each and every library, but as longas the Linux kernel remained, it would still be Linux . The kernel contains device drivers,memory management, process management and communication management.
7 The kernelhacker gurus follow POSIX guidelines which sometimes makes programming easier andsometimes harder. If your program behaves differently on a new Linux kernel release,chances are that a new POSIX guideline has been implemented. For programming infor-mation about the Linux kernel, read the Linux Kernel Hacker s 2. THE Linux KERNELC hapter 3 The Linux libc packagelibc: ISO ,< >, YP functions, crypt functions,some basic shadow routines (by default not included), ..old routines for compatibility in libcompat (by default not activated),english, french or german error messages,bsd compatible screen handling routines in libcurses,bsd compatible routines in libbsd, screen handling routines in libtermcap,database management routines in libdbm,mathematic routines in libm, entry to execute programs in ?
8 ??,byte sex information in libieee ??? (could someone give some infosinstead of laughing ?), user space profiling in wish someone of the Linux libc developers would write this i can say now that there is going to be a change from executable format to the elf (executable and linkable format)which also means a change in building shared both formats ( and elf) are parts of the Linux libc package are under the Library GNU Public License, thoughsome are under a special exception copyright like For commercial binary distribu-tions this means a restriction that forbids statically linked executables. Dynamically linkedexecutables are again a special exception and Richard Stallman of the FSF said:[.]
9 ] But it seems to me that we should unambiguously permit distribution of a dynam-ically linked executable *without* accompanying libraries, provided that the object filesthat make up the executable are themselves unrestricted according to section 5 [..] So I llmake the decision now to permit this. Actually updating the LGPL will have to wait forwhen I have time to make and check a new Goldt The Linux programmer s Guide1112 CHAPTER 3. THE Linux LIBC PACKAGEC hapter 4 System callsA system call is usually a request to the operating system (kernel) to do a hardware/system-specific or privileged operation. As of , 140 system calls have been calls like close() are implemented in the Linux libc.
10 This implementation ofteninvolves calling a macro which eventually calls syscall(). Parameters passed to syscall()are the number of the system call followed by the needed arguments. The actual systemcall numbers can be found in< >while< >gets updatedwith a new libc. If new calls appear that don t have a stub in libc yet, you can use syscall().As an example, you can close a file using syscall() like this (not advised):#include < >extern int syscall(int, ..);int my_close(int filedescriptor){return syscall(SYS_close, filedescriptor);}On the i386 architecture, system calls are limited to 5 arguments besides the systemcall number because of the number of hardware registers. If you use Linux on anotherarchitecture you can check< >for thesyscall macros to see how manyarguments your hardware supports or how many the developers chose to support.