Hands-On System Programming with Linux
Explore Linux system programming interfaces, theory, and practice
Kaiwan N Billimoria
- 794 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
Hands-On System Programming with Linux
Explore Linux system programming interfaces, theory, and practice
Kaiwan N Billimoria
About This Book
Get up and running with system programming concepts in Linux
Key Features
- Acquire insight on Linux system architecture and its programming interfaces
- Get to grips with core concepts such as process management, signalling and pthreads
- Packed with industry best practices and dozens of code examples
Book Description
The Linux OS and its embedded and server applications are critical components of today's software infrastructure in a decentralized, networked universe. The industry's demand for proficient Linux developers is only rising with time. Hands-On System Programming with Linux gives you a solid theoretical base and practical industry-relevant descriptions, and covers the Linux system programming domain. It delves into the art and science of Linux application programmingâ system architecture, process memory and management, signaling, timers, pthreads, and file IO.
This book goes beyond the use API X to do Y approach; it explains the concepts and theories required to understand programming interfaces and design decisions, the tradeoffs made by experienced developers when using them, and the rationale behind them. Troubleshooting tips and techniques are included in the concluding chapter.
By the end of this book, you will have gained essential conceptual design knowledge and hands-on experience working with Linux system programming interfaces.
What you will learn
- Explore the theoretical underpinnings of Linux system architecture
- Understand why modern OSes use virtual memory and dynamic memory APIs
- Get to grips with dynamic memory issues and effectively debug them
- Learn key concepts and powerful system APIs related to process management
- Effectively perform file IO and use signaling and timers
- Deeply understand multithreading concepts, pthreads APIs, synchronization and scheduling
Who this book is for
Hands-On System Programming with Linux is for Linux system engineers, programmers, or anyone who wants to go beyond using an API set to understanding the theoretical underpinnings and concepts behind powerful Linux system programming APIs. To get the most out of this book, you should be familiar with Linux at the user-level logging in, using shell via the command line interface, the ability to use tools such as find, grep, and sort. Working knowledge of the C programming language is required. No prior experience with Linux systems programming is assumed.
Frequently asked questions
Information
Signaling - Part I
- What exactly signals are.
- Why they are useful.
- The available signals.
- How exactly you can handle signals in an application, which really involves many thingsâblocking or unblocking signals, writing safe handlers, getting rid of pesky zombies once and for all, working with apps where the signal volume is high, and more.
Why signals?
- A CPU-intensive process is busy working on a scientific or mathematical calculation (for easy understanding, let's say it's generating primes); recall (from Chapter 3, Resource Limits) that there is an upper limit on CPU usage and that it's been set to a particular value. What if it's breached? The process will be killed by default. Can we prevent this?
- The developer wants to perform a common task: set up a timer and have it expire in, say, 1.5 seconds from now. How will the OS inform the process that the timer has expired?
- On some Sys V Unixes (typically running on enterprise-class servers), what if a sudden power failure occurs? An event is broadcast to all processes (that have expressed an interest in, or subscribed to the event) informing them of the same: they could flush their buffers, and save their data.
- A process has an inadvertent defect (a bug); it makes an invalid memory access. The memory subsystem (well, technically, the MMU and the OS) determines it must be killed. How exactly will it be killed?
- Linux's asynchronous IO (AIO) framework, and many other such scenarios.
The signal mechanism in brief
int main(void)
{
unsigned long int i=1;
while(1) {
printf("Looping, iteration #%02ld ...\n", i++);
(void)sleep(1);
}
exit (EXIT_SUCCESS);
}
$ ./sig1
Looping, iteration #01 ...
Looping, iteration #02 ...
Looping, iteration #03 ...
^C
$
- A process, P comes alive and runs its code.
- The user presses ^C, in effect causing the SIGINT signal to be sent to the process.
- As we have not set up any signal handler, the default signal handling action for this signal, which is part of the OS, is invoked.
- This default signal handling code within the OS causes the process to die.
- Ignore the signal
- Stop the process
- Continue the (previously stopped) process
- Terminate the process
- Terminate the process and emit a core dump