Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
C++ Programming for Linux Systems
C++ Programming for Linux Systems

C++ Programming for Linux Systems: Create robust enterprise software for Linux and Unix-based operating systems

Arrow left icon
Profile Icon Desislav Andreev Profile Icon Stanimir Lukanov
Arrow right icon
$9.99 $36.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.6 (5 Ratings)
eBook Sep 2023 288 pages 1st Edition
eBook
$9.99 $36.99
Paperback
$45.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Desislav Andreev Profile Icon Stanimir Lukanov
Arrow right icon
$9.99 $36.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.6 (5 Ratings)
eBook Sep 2023 288 pages 1st Edition
eBook
$9.99 $36.99
Paperback
$45.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$9.99 $36.99
Paperback
$45.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

C++ Programming for Linux Systems

Getting Started with Linux Systems and the POSIX Standard

This book is about Linux and how we use C++ in Linux environments to manage critical resources. The C++ language is continuously improving, as you’ll explore in the following chapters. Before we go there, we’d like to spend some time in this chapter developing a fundamental understanding of operating systems (OSs). You are going to learn more about the origins of some specific techniques, the system call interface and the Portable Operating System Interface (POSIX).

Your choice of OS matters. Although OSs were created with a single purpose, nowadays their roles differ. Much is expected of them as well. Each OS has its own strengths and weaknesses, which we are going to discuss briefly. Linux is in widespread use across multiple technological areas and has a huge community worldwide, so it is perfect for our practical purposes. In our experience, programming in Linux or other Unix-based OS environments is rather...

Technical requirements

In order to get familiar with the programming environment, the reader must prepare the following:

  • A Linux-based system capable of compiling and executing C++20 (for example, Linux Mint 21)

Getting familiar with the concept of OSs

So, what is an OS? You could probably provide at least one answer, but let’s discuss this briefly as it is important to understand what our computer system truly is and how we manipulate it. Although you might be familiar with most of the information provided here, we are using this chapter to align with you on the matter of OSs and their uses. Some might say that the OS was created to make the hardware work as a whole. Others will argue that it is an aggregation of programs, dedicated to managing the system resources overall. It is crucial to utilize these resources, such as CPU and memory, efficiently. There is also the concept of the OS as an abstraction and an extension of the hardware. Ultimately, we can safely say that the modern OS is a complex entity. It also has additional functions, such as the collection of statistics, multimedia handling, system safety and security, overall stability, reliable error handling, and so on.

...

Getting to know the Linux kernel

Figure 1.1 illustrates an example of a Linux kernel. Based on your needs, the system architecture could look different, but you can observe the three main layers we expect to see in any given Linux system.

These are the user space (running processes and their threads), the kernel space (the running kernel itself, usually a process of its own), and the computer – this could be any kind of computing device, such as a PC, tablet, smartphone, supercomputer, IoT device, and so on. One by one, all the terms observed in the diagram will fall into place as we explain them in the following chapters, so don’t worry if you are not familiar with all of them right now.

Figure 1.1 – Overview of the Linux kernel and the neighboring layers

Figure 1.1 – Overview of the Linux kernel and the neighboring layers

Some interdependencies in the preceding diagram have probably made an impression on you already. For example, see how the device drivers, the respective devices, and the...

Introducing the system call interface and system programming

Of course, the example that we just saw is simplified but gives us some idea about the work that the OS needs to do – in essence, it is responsible for managing and providing resources, but at the same time remains available for other processes’ requests. This is a messy job on modern OSs. Rarely can we do anything about it. So, to have better control and predictability of system behavior, programmers might directly use the OS’s API, called the system call interface.

Important note

The NVM data request is a procedure that benefits from the system call interface, as the OS will be obliged to turn this request into an application binary interface (ABI) call, referring to the respective device driver. Such an operation is known as a system call. Using system calls to implement or execute functions provided by the OS is known as system programming. The system calls are the only entry points to the kernel...

Navigating through files, processes, and threads

If you made it to here – great job! We are going to cover processes and threads thoroughly in Chapter 2, and filesystems in Chapter 3. In the meantime, we will take a short detour here, just to paint a better picture for you, through the definition of three important terms: files, processes, and threads. You probably already noticed two of these in the kernel overview earlier, so we will explain them briefly now in case you are not familiar with them.

File

In short, we require files to represent multiple kinds of resources on our system. The programs we write are files as well. The compiled code, for example, the executable binaries (.bin, .exe), and the libraries are all files (.o, .so, .lib, .dll, and so on). Additionally, we need them for communication mechanisms and for storage management. Do you know what types of files are recognizable on Linux? Let’s brief you on that quickly:

  • Ordinary or regular files...

Running services with init and systemd

Let’s use this opportunity to discuss the init and the systemd process daemons. There are others as well, but we’ve decided to retain our focus on these two. The first one is the initial process, executed on a Linux system by the kernel, and its pid is always 1:

$ ps -p 1
PID TTY          TIME CMD
1 ?        04:53:20 systemd

It is known as the parent of all processes on the system as it is used to initialize, manage, and track other services and daemons. The first init daemon for Linux is called Init and it defines six system states. All system services are mapped to those states, respectively. Its script is used to start processes in a pre-defined order, which is occasionally used by system programmers. One possible reason to use this is to reduce the startup duration of the system. To create a service or edit the script, you could modify...

Portable Operating System Interface (POSIX)

The POSIX standard has the main task of maintaining compatibility between different OSs. Therefore, POSIX is frequently used by both standard application software developers and system programmers. Nowadays, it can be found not only on Unix-like OSs, but in Windows environments as well – for example, Cygwin, MinGW, and Windows Subsystem for Linux (WSL). POSIX defines both the system- and the user-level APIs with one remark: using POSIX, the programmer doesn’t need to distinguish between system calls and library functions.

The POSIX API is frequently used in the C programming language. Thus, it is compilable with C++. Additional functions are provided to the system call interface in a few important areas of system programming: file operations, memory management, process and thread control, networking and communications, and regular expressions – as you can see, it pretty much covers everything that the already existing...

Summary

In this chapter, we have covered the definitions of basic concepts related to OSs. You have learned about Linux’s main kernel structure and its expectations of software design. Real-time OSs were briefly introduced, and we covered the definitions of system calls, the system call interface, and POSIX as well. We’ve also laid the foundations of multiprocessing and multithreading. In the next chapter, we will discuss the process as the main resource user and manager. We will start with some C++20 code. Through this, you will learn about the Linux’s process memory layout, the OS’s process-scheduling mechanism, and how multiprocessing operates plus the challenges it brings. You will also learn some interesting facts about atomic operations.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Master essential skills to build robust Linux systems
  • Explore hands-on examples to demystify crucial development concepts, upskilling your system programming abilities
  • Master the art of creating software for Linux systems and supercharge your C++ skills
  • Purchase of the print or Kindle book includes a free PDF eBook

Description

Around 35 million Linux and almost 2 billion Android users rely on C++ for everything from the simplest embedded and IoT devices to cloud services, supercomputing, and space exploration. To help you produce high-quality software, two industry experts have transformed their knowledge and experience into practical examples in system programming with C++ Programming for Linux Systems. In this book, you'll explore the latest C++20 features, while working on multiple specific use cases. You’ll get familiar with the coroutines and modern approaches in concurrent and multithreaded programming. You'll also learn to reshape your thinking when analyzing system behavior in Linux (POSIX) environments. Additionally, you'll discover advanced discussions and novel solutions for complex challenges, while approaching trivial system operations with a new outlook and learning to choose the best design for your particular case. You can use this workbook as an introduction to system programming and software design in Linux or any Unix-based environment. You’ll also find it useful as a guideline or a supplement to any C++ book. By the end of this book, you’ll have gained advanced knowledge and skills for working with Linux or any Unix-based environment.

Who is this book for?

This book is for every software developer looking to improve and update their C++ development skills. Both students and professionals will find this book useful as the examples are curated to match any area of expertise and are easily adaptable. At the same time, they don’t lose focus of the system specifics. A basic understanding of operating systems’ interfaces is a must along with experience in software development.

What you will learn

  • Use C++20 features to craft elegant, efficient, and modern code for Linux systems
  • Acquire essential system programming skills with hands-on examples
  • Develop a deep understanding of Linux programming, from embedded systems to cloud services
  • Tailor your applications to exploit the strengths and mitigate the weaknesses of different architectures
  • Merge advanced C++, system programming, Linux insights, and architecture to create exceptional software
  • Boost your code quality by using system programming techniques to refine and optimize your codebase

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Sep 22, 2023
Length: 288 pages
Edition : 1st
Language : English
ISBN-13 : 9781805128748
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Sep 22, 2023
Length: 288 pages
Edition : 1st
Language : English
ISBN-13 : 9781805128748
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 140.97
Building Low Latency Applications with C++
$44.99
Expert C++
$49.99
C++ Programming for Linux Systems
$45.99
Total $ 140.97 Stars icon
Banner background image

Table of Contents

14 Chapters
Part 1:Securing the Fundamentals Chevron down icon Chevron up icon
Chapter 1: Getting Started with Linux Systems and the POSIX Standard Chevron down icon Chevron up icon
Chapter 2: Learning More about Process Management Chevron down icon Chevron up icon
Chapter 3: Navigating through the Filesystems Chevron down icon Chevron up icon
Chapter 4: Diving Deep into the C++ Object Chevron down icon Chevron up icon
Chapter 5: Handling Errors with C++ Chevron down icon Chevron up icon
Part 2:Advanced Techniques for System Programming Chevron down icon Chevron up icon
Chapter 6: Concurrent System Programming with C++ Chevron down icon Chevron up icon
Chapter 7: Proceeding with Inter-Process Communication Chevron down icon Chevron up icon
Chapter 8: Using Clocks, Timers, and Signals in Linux Chevron down icon Chevron up icon
Chapter 9: Understanding the C++ Memory Model Chevron down icon Chevron up icon
Chapter 10: Using Coroutines in C++ for System Programming Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.6
(5 Ratings)
5 star 60%
4 star 40%
3 star 0%
2 star 0%
1 star 0%
POE Sep 30, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book starts with good coverage of Linux, the kernel, memory, scheduling mechanisms, and filesystem operations. After those first necessary chapters, C++ is covered in depth. Some of the topics include great depth on the object model, how to handle errors, and concurrency.The level of detail in this book is truly impressive. For example, the section on handling time in Linux using C++ serves as a great reference. The C++ memory model is also covered. I believe that both novice and experienced developers can benefit from this book.Bravo!
Amazon Verified review Amazon
arsalan Oct 04, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The chapters are well-structured, making it easy to follow along and build your expertise gradually. From process management and file systems to error handling and memory management, the book covers a wide range of topics crucial for Linux system programming. The authors' ability to merge advanced C++, system programming, Linux insights, and architecture into a coherent and accessible guide is commendable. The focus on boosting code quality through system programming techniques, refining, and optimizing their codebase is truly commendable.
Amazon Verified review Amazon
Tiny Oct 10, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Too many help books out there offer a title and then wander all over the map. This one is direct and focused on the topic. If you use Linux (who doesn't?) and you want to do your dev in C++ (not me, but a helpful reference), use this book to advance your learning. The book explains the strengths of Linux, and the intricacies of C++ and then how to make the various pieces work effectively together. I can't think of a current reason to run these items together, but we all know that customers have weird requests. If you need a specific reference for these things (C++ on Linux), this is a great option.
Amazon Verified review Amazon
Tans Oct 04, 2023
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
This book is an indispensable resource for those looking to master C++ programming in the context of Linux and Unix-based environments. Its combination of real-world examples, coverage of C++20 features, and expert insights make it a must-read for anyone seeking to excel in system programming. It strikes a balance between catering to different areas of expertise while maintaining a focus on system-specific details.
Amazon Verified review Amazon
D&A Oct 05, 2023
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
One of the standout features of this book is its coverage of C++20, allowing readers to leverage the latest language features to create efficient and modern code tailored for Linux systems. The exploration of concurrent and multithreaded programming, as well as the introduction of coroutines, adds depth to your programming skills.Throughout the book, the authors provide real-world examples and practical exercises that reinforce your learning and help you apply the knowledge gained. Whether you are working on embedded systems, cloud services, or other Linux-based projects, this book equips you with the tools to tackle complex challenges and optimize your codebase.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.