C++ System Programming Cookbook

Book description

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.

Publisher resources

Download Example Code

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. C++ System Programming Cookbook
  3. About Packt
    1. Why subscribe?
  4. Contributors
    1. About the author
    2. About the reviewers
    3. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Code in Action
      4. Conventions used
    4. Sections
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Get in touch
      1. Reviews
  6. Getting Started with System Programming
    1. Technical requirements
    2. Learning the Linux fundamentals - architecture
      1. How to do it...
      2. How it works...
    3. Learning the Linux fundamentals - shell
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    4. Learning the Linux fundamentals - users
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    5. Using a makefile to compile and link a program
      1. How to do it...
      2. How it works...
      3. There's more...
    6. Using GDB to debug a program
      1. How to do it...
      2. How it works...
      3. There's more...
    7. Learning the Linux fundamentals - processes and threads
      1. How to do it...
      2. How it works...
      3. There's more...
    8. Handling a Linux bash error
      1. How to do it...
      2. How it works...
      3. There's more...
    9. Handling Linux code error
      1. How to do it...
      2. How it works...
      3. There's more...
  7. Revisiting C++
    1. Technical requirements
    2. Understanding C++ primitive types
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    3. Lambda expressions
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    4. Automatic type deduction and decltype
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    5. Learning how atomic works
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    6. Learning how nullptr works
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    7. Smart pointers – unique_ptr and shared_ptr
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    8. Learning how move semantics works
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    9. Understanding concurrency
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    10. Understanding the filesystem
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    11. The C++ Core Guidelines
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    12. Adding GSL in your makefile
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    13. Understanding concepts
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    14. Using span
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    15. Learning how Ranges work
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    16. Learning how modules work
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
  8. Dealing with Processes and Threads
    1. Technical requirements
    2. Starting a new process
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    3. Killing a process
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Creating a new thread
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    5. Creating a daemon process
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
  9. Deep Dive into Memory Management
    1. Technical requirements
    2. Learning automatic versus dynamic memory
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    3. Learning when to use unique_ptr, and the implications for size
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    4. Learning when to use shared_ptr, and the implications for size
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    5. Allocating aligned memory
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    6. Checking whether the memory allocated is aligned
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    7. Dealing with memory-mapped I/O
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    8. Dealing with allocators hands-on
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
  10. Using Mutexes, Semaphores, and Condition Variables
    1. Technical requirements
    2. Using POSIX mutexes
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    3. Using POSIX semaphores
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    4. POSIX semaphores advanced usage
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    5. Synchronization building blocks
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    6. Learning inter-thread communication with simple events
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    7. Learning inter-thread communication with condition variables
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
  11. Pipes, First-In First-Out (FIFO), Message Queues, and Shared Memory
    1. Technical requirements
    2. Learning the different types of IPC
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    3. Learning how to use the oldest form of IPC – pipes
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    4. Learning how to use FIFO
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    5. Learning how to use message queues
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    6. Learning how to use shared memory
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
  12. Network Programming
    1. Technical requirements
    2. Learning the basics of connection-oriented communication
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    3. Learning the basics of connectionless-oriented communication
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    4. Learning what a communication endpoint is
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    5. Learning to use TCP/IP to communicate with processes on another machine
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    6. Learning to use UDP/IP to communicate with processes on another machine
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    7. Dealing with endianness
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
  13. Dealing with Console I/O and Files
    1. Technical requirements
    2. Implementing I/O to and from the console
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    3. Learning how to manipulate I/O strings
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    4. Working with files
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
  14. Dealing with Time Interfaces
    1. Technical requirements
    2. Learning about the C++ time interface
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    3. Using the C++20 calendar and time zone
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    4. Learning the Linux timing
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    5. Dealing with time sleep and overruns
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
  15. Managing Signals
    1. Technical requirements
    2. Learning all of the signals and their default actions
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    3. Learning how to ignore a signal
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    4. Learning how to trap a signal
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    5. Learning how to send a signal to another process
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
  16. Scheduling
    1. Technical requirements
    2. Learning to set and get a scheduler policy
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    3. Learning to get the timeslice value
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    4. Learning how to set a nice value
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    5. Learning how to yield the processor
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    6. Learning about processor affinity
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
  17. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: C++ System Programming Cookbook
  • Author(s): Onorato Vaticone
  • Release date: February 2020
  • Publisher(s): Packt Publishing
  • ISBN: 9781838646554