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.
Author(s): Onorato Vaticone
Publisher: Packt Publishing Ltd
Year: 2020
Language: English
Pages: 292
Tags: C++,System Programming
Cover
Title Page
Copyright and Credits
About Packt
Contributors
Table of Contents
Preface
Chapter 1: Getting Started with System Programming
Technical requirements
Learning the Linux fundamentals - architecture
How to do it...
How it works...
Learning the Linux fundamentals - shell
How to do it...
How it works...
There's more...
See also
Learning the Linux fundamentals - users
How to do it...
How it works...
There's more...
See also
Using a makefile to compile and link a program
How to do it...
How it works...
There's more...
Using GDB to debug a program
How to do it...
How it works...
There's more...
Learning the Linux fundamentals - processes and threads
How to do it...
How it works...
There's more...
Handling a Linux bash error
How to do it...
How it works...
There's more...
Handling Linux code error
How to do it...
How it works...
There's more...
Chapter 2: Revisiting C++
Technical requirements
Understanding C++ primitive types
How to do it...
How it works...
There's more...
See also
Lambda expressions
How to do it...
How it works...
There's more...
See also
Automatic type deduction and decltype
How to do it...
How it works...
There's more...
See also
Learning how atomic works
How to do it...
How it works...
There's more...
See also
Learning how nullptr works
How to do it...
How it works...
There's more...
See also
Smart pointers – unique_ptr and shared_ptr
How to do it...
How it works...
There's more...
See also
Learning how move semantics works
How to do it...
How it works...
There's more...
See also
Understanding concurrency
How to do it...
How it works...
There's more...
See also
Understanding the filesystem
How to do it...
How it works...
There's more...
See also
The C++ Core Guidelines
Getting ready
How to do it...
How it works...
There's more...
See also
Adding GSL in your makefile
Getting ready
How to do it...
How it works...
There's more...
See also
Understanding concepts
How to do it...
How it works...
There's more...
See also
Using span
How to do it...
How it works...
There's more...
See also
Learning how Ranges work
How to do it...
How it works...
There's more...
See also
Learning how modules work
How to do it...
How it works...
There's more...
See also
Chapter 3: Dealing with Processes and Threads
Technical requirements
Starting a new process
How to do it...
How it works...
There's more...
See also
Killing a process
Getting ready
How to do it...
How it works...
There's more...
Creating a new thread
How to do it...
How it works...
There's more...
See also
Creating a daemon process
How to do it...
How it works...
There's more...
See also
Chapter 4: Deep Dive into Memory Management
Technical requirements
Learning automatic versus dynamic memory
How to do it...
How it works...
There's more...
See also
Learning when to use unique_ptr, and the implications for size
How to do it...
How it works...
There's more...
See also
Learning when to use shared_ptr, and the implications for size
How to do it...
How it works...
There's more...
See also
Allocating aligned memory
How to do it...
How it works...
There's more...
See also
Checking whether the memory allocated is aligned
How to do it...
How it works...
There's more...
See also
Dealing with memory-mapped I/O
How to do it...
How it works...
There's more...
See also
Dealing with allocators hands-on
How to do it...
How it works...
There's more...
See also
Chapter 5: Using Mutexes, Semaphores, and Condition Variables
Technical requirements
Using POSIX mutexes
How to do it...
How it works...
There's more...
See also
Using POSIX semaphores
How to do it...
How it works...
There's more...
See also
POSIX semaphores advanced usage
How to do it...
How it works...
There's more...
See also
Synchronization building blocks
How to do it...
How it works...
There's more...
See also
Learning inter-thread communication with simple events
How to do it...
How it works...
There's more...
See also
Learning inter-thread communication with condition variables
How to do it...
How it works...
There's more...
See also
Chapter 6: Pipes, First-In First-Out (FIFO), Message Queues, and Shared Memory
Technical requirements
Learning the different types of IPC
How to do it...
How it works...
There's more...
See also
Learning how to use the oldest form of IPC – pipes
How to do it...
How it works...
There's more...
See also
Learning how to use FIFO
How to do it...
How it works...
There's more...
See also
Learning how to use message queues
How to do it...
How it works...
There's more...
See also
Learning how to use shared memory
How to do it...
How it works...
There's more...
See also
Chapter 7: Network Programming
Technical requirements
Learning the basics of connection-oriented communication
How to do it...
How it works...
There's more...
See also
Learning the basics of connectionless-oriented communication
How to do it...
How it works...
There's more...
See also
Learning what a communication endpoint is
How to do it...
How it works...
There's more...
See also
Learning to use TCP/IP to communicate with processes on another machine
How to do it...
How it works...
There's more...
See also
Learning to use UDP/IP to communicate with processes on another machine
How to do it...
How it works...
There's more...
See also
Dealing with endianness
How to do it...
How it works...
There's more...
See also
Chapter 8: Dealing with Console I/O and Files
Technical requirements
Implementing I/O to and from the console
How to do it...
How it works...
There's more...
See also
Learning how to manipulate I/O strings
How to do it...
How it works...
There's more...
See also
Working with files
How to do it...
How it works...
There's more...
See also
Chapter 9: Dealing with Time Interfaces
Technical requirements
Learning about the C++ time interface
How to do it...
How it works...
There's more...
See also
Using the C++20 calendar and time zone
How to do it...
How it works...
There's more...
See also
Learning the Linux timing
How to do it...
How it works...
There's more...
See also
Dealing with time sleep and overruns
How to do it...
How it works...
There's more...
See also
Chapter 10: Managing Signals
Technical requirements
Learning all of the signals and their default actions
How to do it...
How it works...
There's more...
See also
Learning how to ignore a signal
How to do it...
How it works...
There's more...
See also
Learning how to trap a signal
How to do it...
How it works...
There's more...
See also
Learning how to send a signal to another process
How to do it...
How it works...
There's more...
See also
Chapter 11: Scheduling
Technical requirements
Learning to set and get a scheduler policy
How to do it...
How it works...
There's more...
See also
Learning to get the timeslice value
How to do it...
How it works...
There's more...
See also
Learning how to set a nice value
How to do it...
How it works...
There's more...
See also
Learning how to yield the processor
How to do it...
How it works...
There's more...
See also
Learning about processor affinity
How to do it...
How it works...
There's more...
See also
Other Books You May Enjoy
Index