Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
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
Arrow up icon
GO TO TOP
Asynchronous Programming with C++

You're reading from   Asynchronous Programming with C++ Build blazing-fast software with multithreading and asynchronous programming for ultimate efficiency

Arrow left icon
Product type Paperback
Published in Nov 2024
Publisher Packt
ISBN-13 9781835884249
Length 424 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
Javier Reguera Salgado Javier Reguera Salgado
Author Profile Icon Javier Reguera Salgado
Javier Reguera Salgado
Juan Rufes Juan Rufes
Author Profile Icon Juan Rufes
Juan Rufes
Arrow right icon
View More author details
Toc

Table of Contents (21) Chapters Close

Preface 1. Part 1:Foundations of Parallel Programming and Process Management FREE CHAPTER
2. Chapter 1: Parallel Programming Paradigms 3. Chapter 2: Processes, Threads, and Services 4. Part 2: Advanced Thread Management and Synchronization Techniques
5. Chapter 3: How to Create and Manage Threads in C++ 6. Chapter 4: Thread Synchronization with Locks 7. Chapter 5: Atomic Operations 8. Part 3: Asynchronous Programming with Promises, Futures, and Coroutines
9. Chapter 6: Promises and Futures 10. Chapter 7: The Async Function 11. Chapter 8: Asynchronous Programming Using Coroutines 12. Part 4: Advanced Asynchronous Programming with Boost Libraries
13. Chapter 9: Asynchronous Programming Using Boost.Asio 14. Chapter 10: Coroutines with Boost.Cobalt 15. Part 5: Debugging, Testing, and Performance Optimization in Asynchronous Programming
16. Chapter 11: Logging and Debugging Asynchronous Software 17. Chapter 12: Sanitizing and Testing Asynchronous Software 18. Chapter 13: Improving Asynchronous Software Performance 19. Index 20. Other Books You May Enjoy

Services and daemons in Linux

In the realm of Linux operating systems, daemons are a fundamental component that runs quietly in the background, silently executing essential tasks without the direct involvement of an interactive user. These processes are traditionally identified by their names ending with the letter d, such as sshd for the Secure Shell (SSH) daemon and httpd for the web server daemon. They play a vital role in handling system-level tasks crucial for both the operating system and the applications running on it.

Daemons serve an array of purposes, ranging from file serving, web serving, and network communications to logging and monitoring services. They are designed to be autonomous and resilient, starting at system boot and running continuously until the system is shut down. Unlike regular processes initiated and controlled by users, daemons possess distinct characteristics:

  • Background operation:
    • Daemons operate in the background
    • They lack a controlling terminal for direct user interaction
    • They do not require a user interface or manual intervention to perform their tasks
  • User independence:
    • Daemons operate independently of user sessions
    • They function autonomously without direct user involvement
    • They wait for system events or specific requests to trigger their actions
  • Task-oriented focus:
    • Each daemon is tailored to execute a specific task or a set of tasks
    • They are designed to handle specific functions or listen for particular events or requests
    • This ensures efficient task execution

Creating a daemon process involves more than merely running a process in the background. To ensure effective operation as a daemon, developers must consider several key steps:

  1. Detaching from the terminal: The fork() system call is employed to detach the daemon from the terminal. The parent process exits after the fork, leaving the child process running in the background.
  2. Session creation: The setsid() system call creates a new session and designates the calling process as the leader of both the session and the process group. This step is crucial for complete detachment from the terminal.
  3. Working directory change: To prevent blocking the unmounting of the filesystem, daemons typically change their working directory to the root directory.
  4. File descriptor handling: Inherited file descriptors are closed by daemons, and stdin, stdout, and stderr are often redirected to /dev/null.
  5. Signal handling: Proper handling of signals, such as SIGHUP for configuration reloading or SIGTERM for graceful shutdown, is essential for effective daemon management.

Daemons communicate with other processes or daemons through various IPC mechanisms.

Daemons are integral to the architecture of many asynchronous systems, providing essential services without direct user interaction. Some prominent use cases of daemons include the following:

  • Web servers: Daemons such as httpd and nginx serve web pages in response to client requests, handling multiple requests concurrently and ensuring seamless web browsing.
  • Database servers: Daemons such as mysqld and postgresql manage database services, allowing for asynchronous access and manipulation of databases by various applications.
  • File servers: Daemons such as smbd and nfsd provide networked file services, enabling asynchronous file sharing and access across different systems.
  • Logging and monitoring: Daemons such as syslogd and snmpd collect and log system events, providing asynchronous monitoring of system health and performance.

In summary, daemons are essential components of Linux systems, silently performing critical tasks in the background to ensure smooth system operation and efficient application execution. Their autonomous nature and resilience make them indispensable for maintaining system stability and providing essential services to users and applications.

We have seen processes and demons, a special type of process. A process can have one or more threads of execution. In the next section, we will be introducing threads.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image