Systems Programming In Unixlinux Kc Wang pdf download
Systems Programming In Unixlinux Kc Wang pdf download
download
https://ebookbell.com/product/systems-programming-in-unixlinux-
kc-wang-49158110
https://ebookbell.com/product/practical-system-programming-with-c-
pragmatic-example-applications-in-linux-and-unixbased-operating-
systems-1st-ed-sri-manikanta-palakollu-30719010
https://ebookbell.com/product/practical-system-programming-with-c-
pragmatic-example-applications-in-linux-and-unixbased-operating-
systems-1st-edition-sri-manikanta-palakollu-34873360
https://ebookbell.com/product/programming-in-c-unix-system-calls-and-
subroutines-using-c-a-d-marshall-2444736
https://ebookbell.com/product/integer-linear-programming-in-
computational-and-systems-biology-an-entrylevel-text-and-course-dan-
gusfield-11022832
Handson Reactive Programming In Spring 5 Build Cloudready Reactive
Systems With Spring 5 And Project Reactor Dokuka
https://ebookbell.com/product/handson-reactive-programming-in-
spring-5-build-cloudready-reactive-systems-with-spring-5-and-project-
reactor-dokuka-38234934
https://ebookbell.com/product/c-how-to-program-with-case-studies-in-
applications-and-systems-programming-9-global-paul-deitel-harvey-
deitel-43761396
https://ebookbell.com/product/go-in-24-hours-sams-teach-yourself-next-
generation-systems-programming-with-golang-1st-edition-ornbo-23264456
https://ebookbell.com/product/survey-of-methodologies-approaches-and-
challenges-in-parallel-programming-using-highperformance-computing-
systems-pawe-czarnul-10718998
https://ebookbell.com/product/programming-languages-and-systems-in-
computational-economics-and-finance-2002th-edition-jaime-r-
marquez-54965484
K.C. Wang
Systems
Programming
in Unix/Linux
Systems Programming in Unix/Linux
K. C. Wang
Systems Programming
in Unix/Linux
K. C. Wang
School of Electrical Engineering
Washington State University
Pullman, WA, USA
This Springer imprint is published by the registered company Springer Nature Switzerland AG
The registered company address is: Gewerbestrasse 11, 6330 Cham, Switzerland
Dedicated to
Cindy
Preface
vii
viii Preface
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 About This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Roles of Systems Programming . . . . . . . . . . . . . . . . . . . 1
1.3 Objectives of This Book . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3.1 Strengthen Students Programming
Background . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3.2 Applications of Dynamic Data Structures . . . . 2
1.3.3 Process Concept and Process
Management . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3.4 Concurrent Programming . . . . . . . . . . . . . . . . 3
1.3.5 Timer and Time Functions . . . . . . . . . . . . . . . 3
1.3.6 Signals, Signal Processing and IPC . . . . . . . . . 3
1.3.7 File system . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.3.8 TCP/IP and Network Programming . . . . . . . . . 4
1.4 Intended Audience . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.5 Unique Features of This Book . . . . . . . . . . . . . . . . . . . 4
1.6 Use This Book As Textbook in Systems
Programming Courses . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.7 Other Reference Books . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.8 Introduction to Unix . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.8.1 AT&T Unix . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.8.2 Berkeley Unix . . . . . . . . . . . . . . . . . . . . . . . . 8
1.8.3 HP Unix . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.8.4 IBM Unix . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.8.5 Sun Unix . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.9 Introduction to Linux . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.10 Linux Versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.10.1 Debian Linux . . . . . . . . . . . . . . . . . . . . . . . . 9
1.10.2 Ubuntu Linux . . . . . . . . . . . . . . . . . . . . . . . . 9
1.10.3 Linux Mint . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.10.4 RPM-Based Linux . . . . . . . . . . . . . . . . . . . . . 10
1.10.5 Slackware Linux . . . . . . . . . . . . . . . . . . . . . . 10
1.11 Linux Hardware Platforms . . . . . . . . . . . . . . . . . . . . . . 10
ix
x Contents
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449
About the Author
xxi
Introduction
1
Abstract
This chapter presents an introduction to the book. It describes the book’s scope, intended audience
and its suitability as a textbook in Computer Science/Engineering curriculums. It presents a brief
history of Unix, which includes early versions of Unix at Bell Labs, AT&T System V and other
developments of Unix, such as BSD, HP UX, IBM AIX and Sun/Solaris Unix. It describes the
development of Linux and various Linux distributions, which include Debian, Ubuntu, Mint, Red
Hat and Slackware. It lists both the hardware platforms and virtual machines for Linux. It shows
how to install Ubuntu Linux to both VirtualBox and Vmware virtual machines inside the Microsoft
Windows. It explains the startup sequence of Linux, from booting the Linux kernel to user login and
command execution. It describes the Unix/Linux file system organization, file types and commonly
used Unix/Linux commands. Lastly, it describes system administration tasks for users to manage
and maintain their Linux systems.
This book is about systems programming in the Unix/Linux (Thompson and Ritchie 1974, 1978; Bach
1986; Linux 2017) environment. It covers all the essential components of Unix/Linux, which include
process management, concurrent programming, timer and time service, file systems, network program-
ming and MySQL database system. In addition to covering the functionalities of Unix/Linux, it
stresses on programming practice. It uses programming exercises and realistic programming projects
to allow students to practice systems programming with hands-on experiences.
with the needed background to pursue advanced studies in Computer Science/Engineering, such as
operating systems, embedded systems, database systems, data mining, artificial intelligence, computer
networks, network security, distributed and parallel computing.
Computer Science/Engineering students usually take introductory programming courses in their first or
second year. Such courses typically cover basic programming in C, C++ or Java. Due to time
limitations, these courses can only cover the basic syntax of a programming language, data types,
simple program structures and using library functions for I/O. Students coming out of such course are
rather weak in programming skills due to a lack of sufficient practices. For instance, they usually do not
know much about the software tools, the steps of program development and run-time environment of
program executions. The first object of this book is to provide students with the needed background
and skills to do advanced programming. This book covers program development steps in detail. These
include assembler, compiler, linker, link library, executable file contents, program execution image,
function call conventions, parameter passing schemes, local variables, stack frames, link C program
with assembly code, program termination and exception handling. In addition, it also shows how to use
Makefiles to manage large programming projects and how to debug program executions by GDB.
Most elementary data structure courses cover the concepts of link lists, queues, stacks and trees, etc.
but they rarely show where and how are these dynamic data structures used in practice. This book
covers these topics in detail. These include C structures, pointers, link lists and trees. It uses
programming exercises and programming projects to let the students apply dynamic data structures
in real life. Case in point: a programming exercise is for the students to display the stack contents of a
program with many levels of function calls, allowing them to see the function calling sequence, passed
parameters, local variables and stack frames. Another programming exercise is to let students imple-
ment a printf-like function with varying parameters, which requires them to apply parameter passing
schemes to access varying parameters on stack. Yet another programming exercise is to print the
partitions of a disk, in which the extended partitions form a “link list” in the disk, but not by the
conventional pointers as they learned in programming languages. A programming project is to
implement a binary tree to simulate the Unix/Linux file system tree, which supports pwd, ls, cd,
mkdir, rmdir, creat, rm operations as in a real file system. Besides using dynamic data structures, the
programming project allows them to apply a wide range of programming techniques, such as string
tokenization, search for nodes in a tree, insert and delete tree nodes, etc. It also allows them to apply
binary tree traversal algorithms to save binary trees as files and reconstruct binary trees from saved
files.
1.3 Objectives of This Book 3
The major focus of systems programming is the abstract notion of processes, which is rather hard to
grasp. This book uses a simple C program together with a piece of assembly code to let students see
real processes in action. The program implements a multitasking environment to simulate process
operations in an OS kernel. It allows the students to create processes, schedule processes by priority,
run different processes by context switching, maintain process relations by a binary tree, use sleep and
wakeup to implement wait for child process termination, etc. This concrete example makes it much
easier for students to understand processes and process management functions. Then it covers process
management in Unix/Linux in detail, which includes fork(), exit(), wait() and change process execu-
tion image by exec(). It also covers I/O redirection and pipes. It uses a programming project to let the
students implement a sh simulator for command execution. The sh simulator behaves exactly the same
as the bash of Linux. It can execute all Unix/Linux commands with I/O redirections, as well as
compound commands connected by pipes.
Parallel computing is the future of computing. It is imperative to introduce parallel computing and
concurrent programming to CS/CE students at an early stage. This book covers parallel computing and
concurrent programming. It explains the concept of threads and their advantages over processes. It
covers Pthreads (Pthreads 2017) programming in detail. It explains the various kinds of threads
synchronization tools, such as threads join, mutex lock, condition variables, semaphores and barriers.
It demonstrates applications of threads by practical examples, which include matrix computation,
quicksort and solving system of linear equations by concurrent threads. It also introduces the concepts
of race conditions, critical regions, deadlock and deadlock prevention schemes. In addition to using
Pthreads, it uses a programming project to let students experiment with user-level threads, implement
threads synchronization tools and practice concurrent programming by user-level threads.
Timer and time functions are essential to process management and file systems. This book covers the
principle of hardware timers, timer interrupts and time service function in Unix/Linux in detail. It
shows how to use interval timers and timer generated signals in systems programming. In addition, it
uses a programming project to let students implement interval timer support for concurrent tasks.
Signals and signal processing are keys to understanding program exceptions and Inter-Process
Communication (IPC). This book covers signals, signal processing and IPC in Unix/Linux. It explains
signal origins, signal delivery and processing in the OS kernel and the relation between signals and
exceptions. It shows how to install signal catchers to handle program exceptions in user mode. It uses a
programming project to let students use Linux signals and pipes to implement an IPC mechanism for
concurrent tasks to exchange messages.
4 1 Introduction
Besides process management, file system is the second major component of an operating system. This
book provides an in depth coverage of file systems. It describes file operations at different levels and
explains their relationships. These include storage devices, file system support in Unix/Linux kernel,
system calls for file operations, library I/O functions, user commands and sh scripts. It uses a series of
programming exercises to let the students implement a complete EXT2 file system that is totally Linux
compatible. These not only allow the students to have a thorough understanding of file operations but
also provide them with the unique experience of writing a complete file system. Another programming
project is to implement and compare the performances of different I/O buffer management algorithms.
The simulation system supports I/O operations between processes and disk controllers. It allows the
students to practice I/O programming, interrupts processing and synchronization between processes
and I/O devices.
Network programming is the third major component of an operating system. This book covers TCP/IP
protocols, socket API, UDP and TCP programming using sockets and the server-client model in
network computing. A programming project is for the students to implement a server-client based
system for remote file operations across the Internet. As of now, WWW and Internet services have
become an indispensable part of daily lives. It is essential to introduce CS/CE students to this
technology. This book covers HTTP and Web programming in detail. It allows the students to
configure the HTTPD server on their Linux machines to support HTTP programming. It shows how
to use HTML for static Web pages and PHP to create dynamic Web pages. It covers the MySQL
database system, shows how to create and manage databases in both command and batch modes and
interface MySQL with both C and PHP. A programming project is for the students to implement a Web
server to support file operations by HTTP forms and dynamic Web pages using CGI programming.
This book is intended as a textbook for systems programming courses in technically oriented
Computer Science/Engineering curriculums that emphasize both theory and programming practice.
The book contains many detailed working example programs with complete source code. It is also
suitable for self-study by advanced programmers and computer enthusiasts.
This book has many unique features which distinguishes it from other books.
1. This book is self-contained. It includes all the foundation and background information for studying
systems programming. These include program development steps, program execution and termi-
nation, function call conventions, run-time stack usage and link C programs with assembly code. It
also covers C structures, pointers and dynamic data structures, such as link lists, queues and binary
trees. It shows applications of dynamic data structures in system programming.
1.5 Unique Features of This Book 5
2. It uses a simple multitasking system to introduce and illustrate the abstract notion of processes.
The multitasking system allows students to create processes, schedule and run different processes
by context switching, implement process synchronization mechanisms, control and observe
process executions. This unique approach allows the students to have a concrete feeling and better
understanding of process operations in real operating systems.
3. It describes the origin and roles of processes in Unix/Linux in detail, from system booting to INIT
process, daemon processes, login processes and the user sh process. It describes the execution
environment of user processes, such as stdin, stdout, stderr file streams and environment variables.
It also explains how does the sh process execute user commands.
4. It covers process management functions in Unix/Linux in detail. These include fork(), exit(), wait
(), changing process execution image by exec(), I/O redirection and pipes. Moreover, it allows the
students to apply these concepts and programming techniques to implement a sh simulator for
command execution. The sh simulator behaves exactly the same as the standard bash of Linux. It
supports executions of simple commands with I/O redirections, as well as compound commands
connected by pipes.
5. It introduces parallel computing and concurrent programming. It covers Pthreads programming by
detailed examples, which include matrix computation, quicksort and solving systems of linear
equations by concurrent threads, and it demonstrate the use of threads synchronization tools of
join, mutex lock, condition variables and barriers. It also introduces the important concepts and
problems in concurrent programming, such as race conditions, critical regions, deadlock and
deadlock prevention schemes. In addition, it allows the students to experiment with user-level
threads, design and implement threads synchronizing tools, such as threads join, mutex lock,
semaphores and demonstrate the capabilities of user-level threads by concurrent programs. These
allow the students to have a deeper understanding how threads work in Linux.
6. It covers timers and time service functions in detail. It also allows the reader to implement interval
timers for concurrent tasks in a multitasking system.
7. It presents a unified treatment of interrupts and signals, treating signals as interrupts to processes,
similar to interrupts to a CPU. It explains signal sources, signal types, signal generation and signal
processing in great detail. It shows how to install signal catchers to allow processes to handle
signals in user mode. It discusses how to use signals for IPC and other IPC mechanisms in Linux.
It uses a programming project to let the students use Linux signals and pipes to implement an IPC
mechanism for tasks to exchange messages in a multitasking system.
8. It organizes file operations into a hierarchy of different levels, ranging from storage devices, file
system support in Unix/Linux kernel, system calls for file operations, library I/O functions, user
commands and sh scripts. This hierarchical view provides the reader with a complete picture of file
operations. It covers file operations at the various levels in detail and explains their relationships. It
shows how to use system calls to develop file operation commands, such as ls for listing directory
and file information, cat for displaying file contents and cp for copying files.
9. It uses a programming project to lead the students to implement a complete EXT2 file system. The
programming project has been used in the CS360, System Programming course, at Washington
State University for many years, and it has proved to be very successful. It provides students with
the unique experience of writing a complete file system that not only works but is also totally
Linux compatible. This is perhaps the most unique feature of this book.
10. It covers TCP/IP protocols, socket API, UDP and TCP programming using sockets and the server-
client model in network programming. It uses a programming project to let the students implement
a server-client based system for remote file operations across the Internet. It also covers HTTP and
Web programming in detail. It shows how to configure the Linux HTTPD server to support HTTP
6 1 Introduction
programming, and how to use PHP to create dynamic Web pages. It uses a programming project to
let the students implement a Web server to support file operations via HTTP forms and dynamic
Web pages using CGI programming.
11. It emphasizes on programming practice. Throughout the book, it illustrates system programming
techniques by complete and concrete example programs. Above all, it uses a series of program-
ming projects to let students practice system programming. The programming projects include
(1) Implement a binary tree to simulate the Unix/Linux file system tree for file operations
(Chap. 2).
(2) Implement a sh simulator for command executions, including I/O redirections and pipes
(Chap. 3).
(3) Implement user-level threads, threads synchronization and concurrent programming
(Chap. 4).
(4) Implement interval timers for concurrent tasks in a multitasking system (Chap. 5).
(5) Use Linux signals and pipes to implement an IPC mechanism for concurrent task to exchange
messages (Chap. 6).
(6) Convert file pathname to file’s INODE in an EXT2 file system (Chap. 7).
(7) Recursive file copy by system calls (Chap. 8).
(8) Implement a printf-like function for formatted printing using only the basic operation of
putchar() (Chap. 9).
(9) Recursive file copy using sh functions and sh scripts (Chap. 10).
(10) Implement a complete and Linux compatible EXT2 file system (Chap. 11).
(11) Implement and compare I/O buffer management algorithms in an I/O system simulator
(Chap. 12).
(12) Implement a file server and clients on the Internet (Chap. 13).
(13) Implement a file server using HTTP forms and dynamic Web pages by CGI programming
(Chap. 13).
Among the programming projects, (1)–(3), (6)–(9), (12)–(13) are standard programming
assignments of the CS360 course at Washington State University. (10) has been the class project
of the CS360 course for many years. Many of the programming projects, e.g. (12)–(13) and
especially the file system project (10), require the students to form two-person teams, allowing
them to acquire and practice the skills of communication and cooperation with peers in a team-
oriented working environment.
This book is suitable as a textbook for systems programming courses in technically oriented Computer
Science/Engineering curriculums that emphasize both theory and practice. A one-semester course
based on this book may include the following topics.
The problems section of each chapter contains questions designed to review the concepts and
principles presented in the chapter. Many problems are suitable as programming projects to let students
gain more experience and skills in systems programming.
Most materials of this book have been used and tested in the Systems Programming course, CS360,
in EECS at Washington State University. The course has been the backbone of both Computer Science
and Computer Engineering programs in EECS at WSU. The current CS360 course syllabus, class notes
and programming assignments are available for review and scrutiny at
http://www.eecs.wsu.edu/~cs360
The course project is to lead students to implement a complete EXT2 file system that is totally Linux
compatible. The programming project has proved to be the most successful part of the CS360 course,
with excellent feedbacks from both industrial employers and academic institutions.
Due to its importance, systems programming in Unix/Linux has been a popular subject matter in
CS/CE education and also for self-study by advanced programmers. As a result, there are a tremendous
number of books and online articles in this area. Some of these books are listed in the reference section
(Curry 1996; Haviland et al. 1998; Kerrisk 2010; Love 2013; Robbins and Robbins 2003; Rochkind
2008; Stevens and Rago 2013). Many of these books are excellent programmer’s guides, which are
suitable as additional reference books.
Unix (Thompson and Ritchie 1974, 1978) is a general purpose operating system. It was developed by
Ken Thompson and Dennis Ritchie on the PDP-11 minicomputers at Bell Labs in the early 70s. In
1975, Bell Labs released Unix to the general public. Initial recipients of this Unix system were mostly
universities and non-profit institutions. It was known as the V6 Unix. This early version of Unix,
together with the classic book on the C programming language (Kernighan and Ritchie 1988) started
the Unix revolution on Operating Systems, with long-lasting effects even to this day.
Development of Unix at AT&T continued throughout the 1980s, cumulating in the release of the
AT&T System V Unix (Unix System V 2017), which has been the representative Unix of AT&T.
8 1 Introduction
System V Unix was a uniprocessor (single CPU) system. It was extended to multiprocessor versions in
the late 80s (Bach 1986).
Berkeley Unix (Leffler et al. 1989, 1996) refers to a set of variants of the Unix operating system
developed by the Berkeley Software Distribution (BSD) at the University of California, Berkeley, from
1977 to 1985. The most significant contributions of BSD Unix are implementation of the TCP/IP suite
and the socket interface, which are incorporated into almost all other operating systems as a standard
means of networking, which has helped the tremendous growth of the Internet in the 90s. In addition,
BSD Unix advocates open source from the beginning, which stimulated further porting and develop-
ment of BSD Unix. Later releases of BSD Unix provided a basis for several open source development
projects, which include FreeBSD (McKusick et al. 2004), OpenBSD and NetBSD, etc. that are still
ongoing to this day.
1.8.3 HP Unix
HP-UX (HP-UX 2017) is Hewlett Packard’s proprietary implementation of the Unix operating
system, first released in 1984. Recent versions of HP-UX support the HP 9000 series computer
systems, based on the PA-RISC processor architecture, and HP Integrity systems, based on Intel’s
Itanium. The unique features of HP-UX include a built-in logical volume manager for large file
systems and access control lists as an alternative to the standard rwx file permissions of Unix.
AIX (IBM AIX 2017) is a series of proprietary Unix operating systems developed by IBM for several
of its computer platforms. Originally released for the IBM 6150 RISC workstation, AIX now supports
or has supported a wide variety of hardware platforms, including the IBM RS/6000 series and later
POWER and PowerPC-based systems, IBM System I, System/370 mainframes, PS/2 personal
computers, and the Apple Network Server. AIX is based on UNIX System V with BSD4.3-compatible
extensions.
Solaris (Solaris 2017) is a Unix operating system originally developed by Sun Microsystems (Sun OS
2017). Since January 2010, it was renamed Oracle Solaris. Solaris is known for its scalability,
especially on SPARC systems. Solaris supports SPARC-based and x86-based workstations and
servers from Oracle and other vendors.
As can be seen, most Unix systems are proprietary and tied to specific hardware platforms. An
average person may not have access to these systems. This present a challenge to readers who wishes to
practice systems programming in the Unix environment. For this reason, we shall use Linux as the
platform for programming exercises and practice.
1.10 Linux Versions 9
Linux (Linux 2017) is a Unix-like system. It started as an experimental kernel for the Intel x86 based
PCs by Linus Torvalds in 1991. Subsequently, it was developed by a group of people world-wide. A
big milestone of Linux occurred in the late 90s when it combined with GNU (Stallman 2017) by
incorporating many GNU software, such as the GCC compiler, GNU Emacs editor and bash, etc.
which greatly facilitated the further development of Linux. Not long after that, Linux implemented the
TCP/IP suite to access the Internet and ported X11 (X-windows) to support GUI, making it a
complete OS.
Linux includes many features of other Unix systems. In some sense, it represents a union of the
most popular Unix systems. To a large extent, Linux is POSIX compliant. Linux has been ported to
many hardware architectures, such as Motorola, SPARC and ARM, etc. The predominate Linux
platform is still the Intel x86 based PCs, including both desktops and laptops, which are widely
available. Also, Linux is free and easy to install, which makes it popular with computer science
students.
The development of Linux kernel is under the strict supervision of the Linux kernel development
group. All Linux kernels are the same except for different release versions. However, depending on
distributions, Linux has many different versions, which may differ in distribution packages, user
interface and service functions. The following lists some of the most popular versions of Linux
distributions.
Debian is a Linux distribution that emphasizes on free software. It supports many hardware
platforms. Debian distributions use the .deb package format and the dpkg package manager and its
front ends.
Ubuntu is a Linux distribution based on Debian. Ubuntu is designed to have regular releases, a
consistent user experience and commercial support on both desktops and servers. Ubuntu Linux has
several official distributions. These Ubuntu variants simply install a set of packages different from the
original Ubuntu. Since they draw additional packages and updates from the same repositories as
Ubuntu, the same set of software is available in all of them.
Linux Mint is a community-driven Linux distribution based on Debian and Ubuntu. According to
Linux Mint, it strives to be a “modern, elegant and comfortable operating system which is both
powerful and easy to use”. Linux Mint provides full out-of-the-box multimedia support by including
10 1 Introduction
some proprietary software, and it comes bundled with a variety of free and open-source applications.
For this reason, it was welcomed by many beginner Linux users.
Red Hat Linux and SUSE Linux were the original major distributions that used the RPM file format,
which is still used in several package management systems. Both Red Hat and SUSE Linux divided
into commercial and community-supported distributions. For example, Red Hat Linux provides a
community-supported distribution sponsored by Red Hat called Fedora, and a commercially supported
distribution called Red Hat Enterprise Linux, whereas SUSE divided into openSUSE and SUSE Linux
Enterprise
Slackware Linux is known as a highly customizable distribution that stresses on ease of maintenance
and reliability over cutting-edge software and automated tools. Slackware Linux is considered as a
distribution for advanced Linux users. It allows users to choose Linux system components to install
and configure the installed system, allowing them to learn the inner workings of the Linux operating
system.
Linux was originally designed for the Intel x86 based PCs. Earlier versions of Linux run on Intel x86
based PCs in 32-bit protected mode. It is now available in both 32-bit and 64-bit modes. In addition to
the Intel x86, Linux has bee ported to many other computer architectures, which include MC6800 of
Motorola, MIP, SPARC, PowerPC and recently ARM. But the predominant hardware platform of
Linux is still the Intel x86 based PCs, although ARM based Linux for embedded systems are gaining
popularity rapidly.
Presently, most Intel x86 based PCs are equipped with Microsoft Windows, e.g. Windows 7, 8 or
10, as the default operating system. It is fairly easy to install Linux alongside Windows on the same PC
and use dual-boot to boot up either Windows or Linux when the PC starts. However, most users are
reluctant to do so due to either technical difficulty or preference to stay in the Windows environment. A
common practice is to install and run Linux on a virtual machine inside the Windows host. In the
following, we shall show how to install and run Linux on virtual machines inside the Microsoft
Windows 10.
1.12.1 VirtualBox
VirtualBox (VirtualBox 2017) is a powerful x86 and AMD64/Intel64 virtualization product of Oracle.
VirtualBox runs on Windows, Linux, Macintosh, and Solaris hosts. It supports a large number of guest
1.12 Linux on Virtual Machines 11
operating systems, including Windows (NT 4.0, 2000, XP, Vista, Windows 7, Windows 8, Windows
10) and Linux (2.4, 2.6, 3.x and 4.x), Solaris and OpenSolaris, OS/2, and OpenBSD. To install
virtualBox on Windows 10, follow these steps.
Although none of these options seems to be related to the screen resolution, it does change the
resolution to 1024 768 for a normal Ubuntu display screen. Figure 1.2 shows the screen of Ubuntu
on the VirtualBox VM.
Emacs provides an Integrated Development Environment (IDE) for text-edit, compile C programs and
run the resulting binary executables under GDB. We shall cover and demonstrate the emacs IDE in
Chap. 2.
1.12.2 VMware
VMware is another popular VM for x86 based PCs. The full versions of VMware, which include VM
servers, are not free, but VMware Workstation Players, which are sufficient for simple VM tasks,
are free.
It seems that free VMware Player only supports 32-bit VMs. The install steps are identical to above
except the installer disc is the Slackware14.2 install DVD. After installing both Slackware 14.2 and
Ubuntu 15.10, set up LILO to boot up either system when the VM starts up. If the reader installs
Slackware first followed by installing Ubuntu, Ubuntu will recognize Slackware and configure GRUB
for dual boot. The following figure shows the dual-boot menu of LILO (Fig. 1.5).
1.13 Use Linux 15
In a typical Linux system, Linux kernel images are in the /boot directory. Bootable Linux kernel
images are named as
vmlinuz-generic-VERSION_NUMBER
initrd as the initial ramdisk image for the Linux kernel.
BOOT is a 512-byte booter for booting early versions of Linux from floppy disk images. It is no longer
used for Linux booting but it contains some parameters for SETUP to use. SETUP is a piece of 16-bit
and 32-bit assembly code, which provides transition from the 16-bit mode to 32-bit protected mode
during booting. Linux kernel is the actual kernel image of Linux. It is in compressed form but it has a
piece of decompressing code at beginning, which decompresses the Linux kernel image and relocates
it to high memory.
The Linux kernel can be booted up by several different boot-loaders. The most popular Linux boot-
loaders are GRUB and LILO. Alternatively, the HD booter of (Wang 2015) can also be used to boot up
Linux.
During booting, the Linux boot-loader first locates the Linux kernel image (file). Then it loads
For generic Linux kernel images, it also loads an initial ramdisk image, initrd, to high memory. Then it
transfers control to run SETUP code at 0902000, which starts up the Linux kernel. When the Linux
kernel first starts up, it runs on initrd as a temporary root file system. The Linux kernel executes a sh
script, which directs the kernel to load the needed modules for the real root device. When the real root
device is activated and ready, the kernel abandons the initial ramdisk and mounts the real root device as
the root file system, thus completing a two-phase booting of the Linux kernel.
16 1 Introduction
The Linux kernel starts up in the single user mode. It mimics the run-levels of System V Unix to run in
multi-user mode. Then it creates and run the INIT process P1, which creates the various daemon
processes and also terminal processes for users to login. Then the INIT process waits for any child
process to terminate.
Each login process opens three file streams, stdin for input, stdout for output and stderr for error
output, on its terminal. Then it waits for users to login. On Linux systems using X-windows as user
interface, the X-window server usually acts as an interface for users to login. After a user login, the
(pseudo) terminals belong to the user by default.
After login, the user process typically executes the command interpreter sh, which prompts the user for
commands to execute. Some special commands, such as cd (change directory), exit, logout, &, are
performed by sh directly. Non-special commands are usually executable files. For a non-special
command, sh forks a child process and waits for the child to terminate. The child process changes
its execution image to the file and executes the new image. When the child process terminates, it wakes
up the parent sh, which prompts for another command, etc. In addition to simple commands, sh also
supports I/O redirections and compound commands connected by pipes. In addition to built-in
commands, the user may develop programs, compile-link them into binary executable files and run
the programs as commands.
Among the different versions of Linux, we recommend Ubuntu Linux 15.10 or later for the following
reasons.
(1) It is very easy to install. It can be installed online if the user has connection to the Internet.
(2) It is very easy to install additional software packages by
sudo apt-get install PACKAGE
(3) It is updated and improved regularly with new releases.
(4) It has a large user base, with many problems and solutions posted in discussion forums online.
(5) It provides easy connections to wireless networks and access to the Internet.
1.14 Use Ubuntu Linux 17
(1) When installing Ubuntu on a desktop or laptop computer, it will ask for a user name and a
password to create a user account with a default home directory /home/username. When Ubuntu
boots up, it immediately runs in the environment of the user because it already has the default user
logged in automatically. Enter Control-Alter-T to open a pseudo-terminal. Right click the Term
icon and choose “lock to launcher” to lock the Term icon in the menu bar. Subsequently, launch
new terminals by choosing the terminal->new terminal on the menu bar. Each new terminal runs
a sh for the user to execute commands.
(2) For security reasons, the user is an ordinary user, not the root or superuser. In order to run any
privileged commands, the user must enter
sudo command
PATH=$PATH:./
Every time the user opens a pseudo-terminal, sh will execute the .bashrc file first to set PATH to
include the current working directory ./
(4) Many users may have installed 64-bit Ubuntu Linux. Some of the programming exercises and
assignments in this book are intended for 32-bit machines. In 64-bit Linux, use
to generate 32-bit code. If the 64-bit Linux does not take the -m32 option, the user must install
additional support for gcc to generate 32-bit code.
(5) Ubuntu provides an excellent GUI user interface. Many users are so accustomed to the GUI that
they tend to rely on it too much, often wasting time by repeatedly dragging and clicking the
pointing device. In systems programming, the user should also learn how to use command lines
and sh scripts, which are much more general and powerful than GUI.
(6) Nowadays, most users can connect to computer networks. Ubuntu supports both wired and
wireless connections to networks. When Ubuntu runs on a PC/laptop with wireless hardware, it
displays a wireless icon on top and it allows wireless connections by a simple user interface. Open
the wireless icon. It will show a list of available wireless networks near by. Select a network and
open the Edit Connections submenu to edit the connection file by entering the required login
name and password. Close the Edit submenu. Ubuntu will try to login to the selected wireless
network automatically.
18 1 Introduction
The Unix/Linux file system is organized as a tree, which is shown (sideway) in Fig. 1.6.
Unix/Linux considers everything that can store or provide information as a file. In a general sense,
each node of the file system tree is a FILE. In Unix/Linux, files have the following types.
(1). Directory files: A directory may contain other directories and (non-directory) files.
(2). Non-directory files: Non-directory files are either REGULAR or SPECIAL files, which can only
be leaf-nodes in the file system tree. Non-directory files can be classified further as
(2).1 REGULAR files: Regular files are also called ORDINARY files. They contain either ordinary
text or executable binary code.
(2).2 SPECIAL files: Special files are entries in the /dev directory. They represent I/O devices, which
are further classified as
(3). Symbolic LINK files: These are Regular files whose contents are pathnames of other files. As
such, they act as pointers to other files. As an example, the Linux command
ln -s aVeryLongFileName myLink
creates a symbolic link file, mylink, which points to aVeryLongFileName. Access to myLink will be
redirected to the actual file aVeryLongFileName.
1.15 Unix/Linux File System Organization 19
The root node of a Unix/Linux file system tree, symbolized by /, is called the root directory or simply
the root. Each node of the file system tree is specified by a pathname of the form
/a/b/c/d OR a/b/c/d
When using an operating system, the user must learn how to use the system commands. The following
lists the most often used commands in Unix/Linux.
Linux maintains online man (manual) pages in the standard /usr/man/directory. In Ubuntu Linux, it is
in /usr/share/man directory. The man pages are organized into several different categories, denoted by
man1, man2, etc.
20 1 Introduction
/usr/man/
|-- man1: commonly used commands: ls, cat, mkdir ...., etc.
|-- man2: system calls
|-- man3: library functions: strtok, strcat, basename, dirname
etc.
All the man pages are compressed .gz files. They contain text describing how to use the command with
input parameters and options. man is a program, which reads man page files and displays their contents
in a user friendly format. Here are some examples of using man pages.
Whenever needed, the reader should consult the man pages for how to use a specific Linux command.
Many of the so called Unix/Linux systems programming books are essentially condensed versions of
the Unix/Linux man pages.
As in all Linux, user accounts are maintained in the /etc/passwd file, which is owned by the superuser
but readable by anyone. Each user has a line in the /etc/passwd file of the form
loginName:x:gid:uid:usefInfo:homeDir:initialProgram
where the second field x indicates checking user password. Encrypted user passwords are maintained
in the /etc/shadow file. Each line of the shadow file contains the encrypted user password, followed by
optional aging limit information, such as expiration date and time, etc. When a user tries to login with a
login name and password, Linux will check both the /etc/passwd and /etc/shadow files to authenticate
the user. After a user login successfully, the login process becomes the user process by acquiring the
user’s gid and uid, changes directory to the user’s homeDir and executes the listed initialProgram,
which is usually the command interpreter sh.
This may be a pathological case for most users who run Ubuntu Linux on their personal PCs or laptops.
But let’s assume that the reader may want to add a family member to use the same computer but as a
different user. As in all Linux, Ubuntu supports an adduser command, which can be run as
It adds a new user by creating an account and also a default home directory /home/username for the
new user. Henceforth, Ubuntu will display a list of user names in its “About The Computer” menu. The
new user may login to the system by selecting the new username.
For security reasons, the root or superuser account is disabled in Ubuntu, which prevents anyone from
login as the root user (well, not quite; there is a way but I won’t disclose it). sudo (“superuser do”)
allows a user to execute a command as another user, usually the superuser. It temporarily elevates the
user process to the superuser privilege while executing a command. When the command execution
finishes, the user process reverts back to its original privilege level. In order to be able to use sudo, the
user’s name must be in the /etc/sudoers file. To allow a user to issue sudo, simply add a line to sudoers
files, as in
However, the /etc/sudoers file has a very rigid format. Any syntax error in the file could breech the
system security. Linux recommends editing the file only by the special command visudo, which
invokes the vi editor but with checking and validation.
1.17 Summary
This chapter presents an introduction to the book. It describes the book’s scope, intended audience and
its suitability as textbook in Computer Science/Engineering curriculums. It presents a brief history of
Unix, which includes early versions of Unix at Bell Labs, AT&T System V and other developments of
Unix, such as BSD, HP UX, IBM AIX and Sun/Solaris Unix. It describes the development of Linux
and various Linux distributions, which include Debian, Ubuntu, Mint, Red Hat and Slackware. It lists
both the hardware platforms and virtual machines for Linux. It shows how to install Ubuntu Linux to
both VirtualBox and Vmware virtual machines inside the Microsoft Windows. It explains the startup
sequence of Linux, from booting the Linux kernel to user login and command execution. It describes
the Linux file system organization, file types and commonly used Unix/Linux commands. Lastly, it
describes some system administration tasks for users to manage and maintain their Linux systems.
References
Bach M., “The Design of the UNIX Operating System”, Prentice-Hall, 1986
Curry, David A., Unix Systems Programming for SRV4, O’Reilly, 1996.
Haviland, Keith, Gray, Dian, Salama, Ben, Unix System Programming, Second Edition, Addison-Wesley, 1998.
HP-UX, http://www.operating-system.org/betriebssystem/_english/bs-hpux.htm, 2017
IBM AIX, https://www.ibm.com/power/operating-systems/aix, 2017
Kernighan, B.W., Ritchie D.M, “The C Programming Language” 2nd Edition, 1988
Kerrisk, Michael, The Linux Programming Interface: A Linux and UNIX System Programming Handbook, 1st Edition,
No Starch Press Inc, 2010.
Leffler, S.J., McKusick, M. K, Karels, M. J. Quarterman, J., “The Design and Implementation of the 4.3BSD UNIX
Operating System”, Addison Wesley, 1989
Leffler, S.J., McKusick, M. K, Karels, M. J. Quarterman, J., “The Design and Implementation of the 4.4BSD UNIX
Operating System”, Addison Wesley, 1996
22 1 Introduction
Abstract
This chapter covers the background information needed for systems programming. It introduces several
GUI based text editors, such as vim, gedit and EMACS, to allow readers to edit files. It shows how to
use the EMACS editor in both command and GUI mode to edit, compile and execute C programs. It
explains program development steps. These include the compile-link steps of GCC, static and dynamic
linking, format and contents of binary executable files, program execution and termination. It explains
function call conventions and run-time stack usage in detail. These include parameter passing, local
variables and stack frames. It also shows how to link C programs with assembly code. It covers the
GNU make facility and shows how to write Makefiles by examples. It shows how to use the GDB
debugger to debug C programs. It points out the common errors in C programs and suggests ways
to prevent such errors during program development. Then it covers advanced programming techniques.
It describes structures and pointer in C. It covers link lists and list processing by detailed examples. It
covers binary trees and tree traversal algorithms. The chapter cumulates with a programming project,
which is for the reader to implement a binary tree to simulate operations in the Unix/Linux file system
tree. The project starts with a single root directory node. It supports mkdir, rmdir, creat, rm, cd, pwd, ls
operations, saving the file system tree as a file and restoring the file system tree from saved file. The
project allows the reader to apply and practice the programming techniques of tokenizing strings,
parsing user commands and using function pointers to invoke functions for command processing.
2.1.1 Vim
Vim (Linux Vi and Vim Editor 2017) is the standard built-in editor of Linux. It is an improved version
of the original default Vi editor of Unix. Unlike most other editors, vim has 3 different operating
modes, which are
When vim starts, it is in the default Command mode, in which most keys denote special commands.
Examples of command keys for moving the cursor are
h: move cursor one char to the left; l: move cursor one char to the right
j: move cursor down one line; k: move cursor up one line
When using vim inside X-window, cursor movements can also be done by arrow keys. To enter text for
editing, the user must switch vim into Insert mode by entering either the i (insert) or a (append)
command:
To exit Insert mode, press the ESC key one or more times. While in Command mode, enter the : key to
enter the Last-line mode, which is for saving texts as files or exit vim:
Although many Unix users are used to the different operating modes of vim, others may find it
somewhat unnatural and inconvenient to use as compared with other Graphic User Interface (GUI)
based editors. The following editors belong to what is commonly known as What You See Is What
You Get (WYSIWYG) type of editors. In a WYSIWYG editor, a user may enter text, move the cursor
by arrow keys, just like in regular typing. Commands are usually formed by entering a special meta
key, together with, or followed by, a letter key sequence. For example,
Since there is no mode switching necessary, most users, especially beginners, prefer WYSUWYG type
editors over vim.
2.1.2 Gedit
Gedit is the default text editor of the GNOME desktop environment. It is the default editor of Ubuntu,
as well as other Linux that uses the GNOME GUI user interface. It includes tools for editing both
source code and structured text such as markup languages.
2.1.3 Emacs
Emacs (GNU Emacs 2015) is a powerful text editor, which runs on many different platforms. The
most popular version of Emacs is GNU Emacs, which is available in most Linux distributions.
2.2 Use Text Editors 25
All the above editors support direct inputs and editing of text in full screen mode. They also support
search by keywords and replace strings by new text. To use these editors, the user only needs to learn a
few basics, such as how to start up the editor, input text for editing, save edited texts as files and then
exit the editor.
Depending on the Unix/Linux distribution, some of the editors may not be installed by default. For
example, Ubuntu Linux usually comes with gedit, nano and vim, but not emacs. One nice feature of
Ubuntu is that, when a user tries to run a command that is not installed, it will remind the user to install
it. As an example, if a user enters
emacs filename
Ubuntu will display a message saying “The program emacs is currently not installed. You can install it
by typing apt-get install emacs”. Similarly, the user may install other missing software packages by the
apt-get command.
All text editors are designed to perform the same task, which is to allow users to input texts, edit them
and save the edited texts as files. As noted above, there are many different text editors. Which text
editor to use is a matter of personal preference. Most Linux users seem to prefer either gedit or emacs
due to their GUI interface and ease to use. Between the two, we strongly recommend emacs. The
following shows some simple examples of using emacs to create text files.
to invoke the emacs editor with an optional file name, e.g. t.c. This will start up emacs in a separate
window as show in Fig. 2.1. On top of the emacs window is a menu bar, each of which can be opened
to show additional commands, which the user can invoke by clicking on the menu icons. To begin
with, we shall not use the menu bar and focus on the simple task of creating a C program source file.
When emacs starts, if the file t.c already exists, it will open the file and load its contents into a buffer for
editing. Otherwise, it will show an empty buffer, ready for user inputs. Fig. 2.1 shows the user input
lines. Emacs recognizes any .c file as source file for C programs. It will indent the lines in accordance
with the C code line conventions, e.g. it will match each left { with a right }with proper indentations
automatically. In fact, it can even detect incomplete C statements and show improper indentations to
alert the user of possible syntax errors in the C source lines.
After creating a source file, enter the meta key sequence Control-x-c to save the file and exit. If the
buffer contains modified and unsaved text, it will prompt the user to save file, as shown on the bottom
line of Fig. 2.2. Entering y will save the file and exit emacs. Alternatively, the user may also click the
Save icon on the menu bar to save and exit.
26 2 Programming Background
At the top of the emacs window is a menu bar, which includes the icons
The File menu supports the operations of open file, insert file and save files. It also supports printing
the editing buffer, open new windows and new frames.
The Edit menu supports search and replace operations.
The Options menu supports functions to configure emacs operations.
The Buffers menu supports selection and display of buffers.
The Tools menu supports compilation of source code, execution of binary executables and debugging.
The C menu supports customized editing for C source code.
The Help menu provides support for emacs usage, such as a simple emacs tutorial.
As usual, clicking on a menu item will display a table of submenus, allowing the user to choose
individual operations. Instead of commands, the user may also use the emacs menu bar to do text
editing, such as undo last operation, cut and past, save file and exit, etc.
Emacs is more than a text editor. It provides an Integrated Development Environment (IDE) for
software development, which include compile C programs, run executable images and debugging
2.3 Program Development 27
program executions by GDB. We shall illustrate the IDE capability of emacs in the next section on
program development.
(1). Create source files: Use a text editor, such as gedit or emacs, to create one or more source files of a
program. In systems programming, the most important programming languages are C and assembly.
We begin with C programs first.
Standard comment lines in C comprises matched pairs of /* and */. In addition to the standard
comments, we shall also use // to denote comment lines in C code for convenience. Assume that t1.c
and t2.c are the source files of a C program.
2.3.2 Variables in C
Variables in C programs can be classified as global, local, static, automatic and registers, etc. as
shown in Fig. 2.3.
Global variables are defined outside of any function. Local variables are defined inside functions.
Global variables are unique and have only one copy. Static globals are visible only to the file in which
they are defined. Non-static globals are visible to all the files of the same program. Global variables
can be initialized or uninitialized. Initialized globals are assigned values at compile time. Uninitialized
globals are cleared to 0 when the program execution starts. Local variables are visible only to the
function in which they are defined. By default, local variables are automatic; they come into existence
28 2 Programming Background
when the function is entered and they logically disappear when the function exits. For register
variables, the compiler tries to allocate them in CPU registers. Since automatic local variables do
not have any allocated memory space until the function is entered, they cannot be initialized at compile
time. Static local variables are permanent and unique, which can be initialized. In addition, C also
supports volatile variables, which are used as memory-mapped I/O locations or global variables that
are accessed by interrupt handlers or multiple execution threads. The volatile keyword prevents the C
compiler from optimizing the code that operates on such variables.
In the above t1.c file, g is an initialized global, h is an uninitialized global and s is a static global.
Both g and h are visible to the entire program but s is visible only in the t1.c file. So t2.c can reference g
by declaring it as extern, but it cannot reference s because s is visible only in t1.c. In the main()
function, the local variables a, b are automatic and c is static. Although the local variable a is defined as
int a ¼ 1, this is not an initialization because a does not yet exist at compile time. The generated code
will assign the value 1 to the current copy of a when main() is actually entered.
(2). Use gcc to convert the source files into a binary executable, as in
which generates a binary executable file named a.out. In Linux, cc is linked to gcc, so they are
the same.
(3). What’s gcc? gcc is a program, which consists of three major steps, as shown in Fig. 2.4.
Step 1. Convert C source files to assembly code files: The first step of cc is to invoke the C
COMPILER, which translates .c files into .s files containing assembly code of the target machine.
The C compiler itself has several phases, such as preprocessing, lexical analysis, parsing and code
generations, etc, but the reader may ignore such details here.
Step 2. Convert assembly Code to OBJECT code: Every computer has its own set of machine
instructions. Users may write programs in an assembly language for a specific machine. An
ASSEMBLER is a program, which translates assembly code into machine code in binary form.
The resulting .o files are called OBJECT code. The second step of cc is to invoke the ASSEMBLER
to translate .s files to .o files. Each .o file consists of
2.3 Program Development 29
There are two ways to create a binary executable, known as static linking and dynamic linking. In
static linking, which uses a static library, the linker includes all the needed library function code and
data into a.out. This makes a.out complete and self-contained but usually very large. In dynamic
linking, which uses a shared library, the library functions are not included in a.out but calls to such
functions are recorded in a.out as directives. When execute a dynamically linked a.out file, the
operating system loads both a.out and the shared library into memory and makes the loaded library
code accessible to a.out during execution. The main advantages of dynamic linking are:
Libraries used for dynamic linking are known as Dynamic Linking Libraries (DLLs). They are
called Shared Libraries (.so files) in Linux. Dynamically loaded (DL) libraries are shared libraries
which are loaded only when they are needed. DL libraries are useful as plug-ins and dynamically
loaded modules.
Although the default binary executable is named a.out, the actual file format may vary. Most C
compilers and linkers can generate executable files in several different formats, which include
(1) Flat binary executable: A flat binary executable file consists only of executable code and
initialized data. It is intended to be loaded into memory in its entirety for execution directly. For
example, bootable operating system images are usually flat binary executables, which simplifies
the boot-loader.
(2) a.out executable file: A traditional a.out file consists of a header, followed by code, data and bss
sections. Details of the a.out file format will be shown in the next section.
(3) ELF executable file: An Executable and Linking Format (ELF) (Youngdale 1995) file consists of
one or more program sections. Each program section can be loaded to a specific memory address.
In Linux, the default binary executables are ELF files, which are better suited to dynamic linking.
For the sake of simplicity, we consider the traditional a.out files first. ELF executables will be covered
in later chapters. An a.out file consists of the following sections:
(1) header: the header contains loading information and sizes of the a.out file, where
tsize ¼ size of Code section;
dsize ¼ size of Data section containing initialized globals and static locals;
bsize ¼ size of bss section containing uninitialized globals and static locals;
total_size ¼ total size of a.out to load.
(2) Code Section: also called the Text section, which contains executable code of the program. It
begins with the standard C startup code crt0.o, which calls main().
(3) Data Section: The Data section contains initialized global and static data.
(4) Symbol table: optional, needed only for run-time debugging.
Note that the bss section, which contains uninitialized global and static local variables, is not in the a.
out file. Only its size is recorded in the a.out file header. Also, automatic local variables are not in a.out.
Figure 2.5 shows the layout of an a.out file.
In Fig. 2.5, _brk is a symbolic mark indicating the end of the bss section. The total loading size of a.
out is usually equal to _brk, i.e. equal to tsize+dsize+bsize. If desired, _brk can be set to a higher value
for a larger loading size. The extra memory space above the bss section is the HEAP area for dynamic
memory allocation during execution.
Random documents with unrelated
content Scribd suggests to you:
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright law
in the United States and you are located in the United States, we do
not claim a right to prevent you from copying, distributing,
performing, displaying or creating derivative works based on the
work as long as all references to Project Gutenberg are removed. Of
course, we hope that you will support the Project Gutenberg™
mission of promoting free access to electronic works by freely
sharing Project Gutenberg™ works in compliance with the terms of
this agreement for keeping the Project Gutenberg™ name associated
with the work. You can easily comply with the terms of this
agreement by keeping this work in the same format with its attached
full Project Gutenberg™ License when you share it without charge
with others.
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the
terms of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.
• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.
Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.
ebookbell.com