
C++ System Programming Cookbook
Practical recipes for Linux system-level programming using the latest C++ features
- 292 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
C++ System Programming Cookbook
Practical recipes for Linux system-level programming using the latest C++ features
About this book
A problem-solution-based guide to help you overcome hurdles effectively while working with kernel APIs, filesystems, networks, threads, and process communications
Key Features
- Learn to apply the latest C++ features (from C++11, 14, 17, and 20) to facilitate systems programming
- Create robust and concurrent systems that make the most of the available hardware resources
- Delve into C++ inbuilt libraries and frameworks to design robust systems as per your business needs
Book Description
C++ is the preferred language for system programming due to its efficient low-level computation, data abstraction, and object-oriented features. System programming is about designing and writing computer programs that interact closely with the underlying operating system and allow computer hardware to interface with the programmer and the user. The C++ System Programming Cookbook will serve as a reference for developers who want to have ready-to-use solutions for the essential aspects of system programming using the latest C++ standards wherever possible.
This C++ book starts out by giving you an overview of system programming and refreshing your C++ knowledge. Moving ahead, you will learn how to deal with threads and processes, before going on to discover recipes for how to manage memory. The concluding chapters will then help you understand how processes communicate and how to interact with the console (console I/O). Finally, you will learn how to deal with time interfaces, signals, and CPU scheduling.
By the end of the book, you will become adept at developing robust systems applications using C++.
What you will learn
- Get up to speed with the fundamentals including makefile, man pages, compilation, and linking and debugging
- Understand how to deal with time interfaces, signals, and CPU scheduling
- Develop your knowledge of memory management
- Use processes and threads for advanced synchronizations (mutexes and condition variables)
- Understand interprocess communications (IPC): pipes, FIFOs, message queues, shared memory, and TCP and UDP
- Discover how to interact with the console (console I/O)
Who this book is for
This book is for C++ developers who want to gain practical knowledge of systems programming. Though no experience of Linux system programming is assumed, intermediate knowledge of C++ is necessary.
Frequently asked questions
- Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
- Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Information
Revisiting C++
- Understanding C++ primitive types
- Lambda expressions
- Automatic type deduction and decltype
- Learning how atomic works
- Learning how nullptr works
- Smart pointers – unique_ptr and shared_ptr
- Learning how semantics works
- Understanding concurrency
- Understanding the filesystem
- The C++ Core Guidelines
- Adding GSL to your makefile
- Understanding concepts
- Using span
- Learning how Ranges work
- Learning how modules work
Technical requirements
- Download and install the Docker Engine from www.docker.com.
- Pull the image from Docker Hub: docker pull kasperondocker/system_programming_cookbook:latest.
- The image should now be available. Type in the following command to view the image: docker images.
- Now, you should have the following image: kasperondocker/system_programming_cookbook.
- Run the Docker image with an interactive shell with the help of the following command: docker run -it --cap-add sys_ptrace kasperondocker/system_programming_cookbook:latest /bin/bash.
- The shell on the running container is now available. Use root@39a5a8934370/# cd /BOOK/ to get all the programs that have been developed for the chapters in this book.
Understanding C++ primitive types
How to do it...
- First, open a new Terminal and type in the following program:
#include <iostream>
#include <limits>
int main ()
{
// integral types section
std::cout << "char " << int(std::numeric_limits<char>::min())
<< "-" << int(std::numeric_limits<char>::max())
<< " size (Byte) =" << sizeof (char) << std::endl;
std::cout << "wchar_t " << std::numeric_limits<wchar_t>::min()
<< "-" << std::numeric_limits<wchar_t>::max()
<< " size (Byte) ="
<< sizeof (wchar_t) << std::endl;
std::cout << "int " << std::numeric_limits<int>::min() << "-"
<< std::numeric_limits<int>::max() << " size
(Byte) ="
<< sizeof (int) << std::endl;
std::cout << "bool " << std::numeric_limits<bool>::min() << "-"
<< std::numeric_limits<bool>::max() << "
size (Byte) ="
<< sizeof (bool) << std::endl;
// floating point types
std::cout << "float " << std::numeric_limits<float>::min() <<
"-"
<< std::numeric_limits<float>::max() << " size
(Byte) ="
<< sizeof (float) << std::endl;
std::cout << "double " << std::numeric_limits<double>::min()
<< "-"
<< std::numeric_limits<double>::max() << " size
(Byte) ="
<< sizeof (double) << std::endl;
return 0;
}
- Next, build (compile and link) g++ primitives.cpp.
- This will produce an executable fil...
Table of contents
- Title Page
- Copyright and Credits
- About Packt
- Contributors
- Preface
- Getting Started with System Programming
- Revisiting C++
- Dealing with Processes and Threads
- Deep Dive into Memory Management
- Using Mutexes, Semaphores, and Condition Variables
- Pipes, First-In First-Out (FIFO), Message Queues, and Shared Memory
- Network Programming
- Dealing with Console I/O and Files
- Dealing with Time Interfaces
- Managing Signals
- Scheduling
- Other Books You May Enjoy