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
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
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
€18.99 per month
Full star icon Full star icon Full star icon Full star icon Half star icon 4.6 (5 Ratings)
Paperback Sep 2023 288 pages 1st Edition
eBook
€18.99 €27.99
Paperback
€34.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Desislav Andreev Profile Icon Stanimir Lukanov
Arrow right icon
€18.99 per month
Full star icon Full star icon Full star icon Full star icon Half star icon 4.6 (5 Ratings)
Paperback Sep 2023 288 pages 1st Edition
eBook
€18.99 €27.99
Paperback
€34.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€18.99 €27.99
Paperback
€34.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781805129004
Category :
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

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

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.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
€189.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
€264.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 106.97
C++ Programming for Linux Systems
€34.99
Expert C++
€37.99
Building Low Latency Applications with C++
€33.99
Total 106.97 Stars icon

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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.