Share E-Book

AuthorAnil Kumar Rangisetti

Master essential C programming skills to develop efficient and reliable system software and applications. Whether you are a system, network, or cloud engineer—this comprehensive guide is designed to help you tackle complex C programming challenges. Throughout this book, you will start by learning basic computer system architecture and essential operating systems concepts to implement reliable and efficient C code. You will then progress through essential C programming skills, including arrays, strings, unions, pointers, and memory management, while practicing runtime error handling and best practices. Next, you will be ready for more advanced topics, like system and network programming, before concluding with a deep dive into Linux namespaces and their role in virtualization in cloud environments. With an emphasis on real-world applications and best practices, this book allows you to experiment with the foundational and advanced constructs for important use cases. What You Will Learn: • Implement reliable C programming techniques for handing arrays, struct, pointers, and memory. • Inspect and manage C processes and threads in a runtime environment. • Learn essential C socket programming skills, error handing, and usage of socket options to handle network applications reliability. • Master fundamentals of virtualization concepts using C programming and Linux namespaces. Who This Book is for: Beginner System, Network and Cloud Engineers, though intermediate and advanced users will also benefit from mastering essential skill sand exploring advanced coverage.

AI Reading Assistant

Summary and highlights from this book's index; jump to passages in the text

Passage locations
Tags
No tags
ISBN: 8868818043
Publisher: Apress
Publish Year: 2026
Language: 英文
Pages: 733
File Format: PDF
File Size: 19.9 MB
Support Statistics
¥.00 · 0times
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

C Programming for System, Network, and Cloud Engineers Techniques for Processes, Memory, Network Applications, and Linux Namespaces — Dr Anil Kumar Rangisetti
C Programming for System, Network, and Cloud Engineers Techniques for Processes, Memory, Network Applications, and Linux Namespaces Dr Anil Kumar Rangisetti
C Programming for System, Network, and Cloud Engineers: Techniques for Processes, Memory, Network Applications, and Linux Namespaces ISBN-13 (pbk): 979-8-8688-1804-2 ISBN-13 (electronic): 979-8-8688-1805-9 https://doi.org/10.1007/979-8-8688-1805-9 Copyright © 2026 by Dr Anil Kumar Rangisetti This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Managing Director, Apress Media LLC: Welmoed Spahr Acquisitions Editor: Melissa Duffy Editorial Assistant: Gryffin Winkler Cover designed by eStudioCalamar Cover image designed by Niklas Bischop on unsplash.com Distributed to the book trade worldwide by Springer Science+Business Media New York, 1 New York Plaza, New York, NY 10004. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a Delaware LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. For information on translations, please e-mail booktranslations@springernature.com; for reprint, paperback, or audio rights, please e-mail bookpermissions@springernature.com. Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web page at http://www.apress.com/bulk-sales. Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub. For more detailed information, please visit https://www.apress.com/gp/services/ source-code. If disposing of this product, please recycle the paper Dr Anil Kumar Rangisetti Opp G Pullareddy Engineering College Balaji Villas 3rd Phase, A Blk, Plot A65 Kurnool, Andhra Pradesh, India
To all my teachers, especially Dr. Bheemarjuna Reddy and Shri Badrinadh, for identifying my strengths, giving me wonderful opportunities to work with them, and guiding me to achieve my goals. To my lovely wife, Sravani, for being a wonderful partner and supporting me in all situations. Without her love and support, I could not have accomplished this work. —Dr. Anil Kumar Rangisetti
v Table of Contents About the Author ��������������������������������������������������������������������������������������������������� xiii About the Technical Reviewer ���������������������������������������������������������������������������������xv Acknowledgments �������������������������������������������������������������������������������������������������xvii Introduction ������������������������������������������������������������������������������������������������������������xix Chapter 1: Basic Computer System Architecture and Essential Operating System Concepts ������������������������������������������������������������������������������������������������������ 1 Basic Computer System Architecture ������������������������������������������������������������������������������������������� 2 CPU Architecture ���������������������������������������������������������������������������������������������������������������������� 3 Memory Hierarchy ������������������������������������������������������������������������������������������������������������������� 5 CPU and IO Device Interactions ����������������������������������������������������������������������������������������������� 6 Inspect System Configurations on a Linux OS ������������������������������������������������������������������������� 7 Operating System Responsibilities ��������������������������������������������������������������������������������������������� 11 Users Program Access to OS Services ���������������������������������������������������������������������������������� 13 OS Process Management Activities and Services ����������������������������������������������������������������� 16 Importance of Compiler, Linker, and Loader �������������������������������������������������������������������������������� 23 Compiler �������������������������������������������������������������������������������������������������������������������������������� 24 Compiler Options to Handle Runtime Errors �������������������������������������������������������������������������� 28 Runtime Environment of a Process ��������������������������������������������������������������������������������������������� 31 Process Memory Layout �������������������������������������������������������������������������������������������������������� 31 Process Execution Environment �������������������������������������������������������������������������������������������� 34 Process Reliability and Security Issues ��������������������������������������������������������������������������������� 40 C Programmer Powers and Responsibilities ������������������������������������������������������������������������������� 44 C Programming Powers ��������������������������������������������������������������������������������������������������������� 45 C Programmer Responsibilities ��������������������������������������������������������������������������������������������� 47 Summary������������������������������������������������������������������������������������������������������������������������������������� 50
vi Chapter 2: Quick Revision of Powerful C Constructs ���������������������������������������������� 51 Procedure-Oriented Programming ���������������������������������������������������������������������������������������������� 52 Understand C Functions’ Memory Layout and Execution Procedure ������������������������������������� 56 Recursive Functions �������������������������������������������������������������������������������������������������������������� 71 Nested Functions in GNU C ���������������������������������������������������������������������������������������������������� 77 Arrays ������������������������������������������������������������������������������������������������������������������������������������������ 81 Powerful Ways for Organizing Array’s Data Elements and Accessing ����������������������������������� 84 Hands-On Activities for Organizing Array’s Data Elements and Accessing Them Efficiently ��������������������������������������������������������������������������������������������������������������������� 91 Strings and Buffers ������������������������������������������������������������������������������������������������������������������� 100 Strings Processing Hands-On Activities ������������������������������������������������������������������������������ 105 C Structures ������������������������������������������������������������������������������������������������������������������������������ 112 Passing Structure Variables Between Functions ����������������������������������������������������������������� 115 Structure and Its Data Members’ Memory Layout ��������������������������������������������������������������� 117 Hands-On Activity-1 ������������������������������������������������������������������������������������������������������������� 118 Power of C Structures for Modeling ������������������������������������������������������������������������������������ 123 Hands-On Activity-2 ������������������������������������������������������������������������������������������������������������� 128 C Unions ������������������������������������������������������������������������������������������������������������������������������������ 132 An Important Use Case of Unions ���������������������������������������������������������������������������������������� 134 Hands-On Activity ���������������������������������������������������������������������������������������������������������������� 135 Summary����������������������������������������������������������������������������������������������������������������������������������� 140 Practice Tasks ��������������������������������������������������������������������������������������������������������������������������� 141 Chapter 3: Practice C Programming with Important Tools ����������������������������������� 143 Compilation and Linking Techniques for Enhancing Programming Skills ��������������������������������� 144 gcc Compilation Options for Performance Tuning ��������������������������������������������������������������� 145 gcc Compilation Options for Linking ������������������������������������������������������������������������������������ 151 gcc Compilation Options for Secured Code ������������������������������������������������������������������������� 161 Memory Access Errors Handling Techniques and Tools ������������������������������������������������������������ 172 Memory and Other Important Errors Handling gcc Options for Reliable Code �������������������� 172 Memory Error Handling Using Valgrind ������������������������������������������������������������������������������� 181 Table of ConTenTs
vii Code Coverage Analysis for Avoiding Performance Issues ������������������������������������������������������� 183 Code Coverage Tools (gcc and gcov) Usage Steps �������������������������������������������������������������� 185 Hands-On Activity ���������������������������������������������������������������������������������������������������������������� 188 GDB: The GNU Project Debugger ����������������������������������������������������������������������������������������������� 195 Go Through a Code Execution and Inspect the Code and Data �������������������������������������������� 195 Inspect the Code and Data Using gdb Commands �������������������������������������������������������������� 202 Handle Application Runtime Errors �������������������������������������������������������������������������������������� 209 Summary����������������������������������������������������������������������������������������������������������������������������������� 219 Practice Tasks ��������������������������������������������������������������������������������������������������������������������������� 220 Chapter 4: Power of C: Pointers ���������������������������������������������������������������������������� 223 Importance of Pointer Programming ����������������������������������������������������������������������������������������� 224 Basic Concepts of C Pointers ����������������������������������������������������������������������������������������������� 225 Use Cases of C Pointers ������������������������������������������������������������������������������������������������������� 228 Pointers Flexible Traversals ������������������������������������������������������������������������������������������������� 234 Efficient and Reliable Ways to Access Arrays and Strings Using Pointers �������������������������������� 236 Pointers to Array Subparts ��������������������������������������������������������������������������������������������������� 237 Pointers to Multidimensional Arrays ������������������������������������������������������������������������������������ 238 Pointers to Strings ��������������������������������������������������������������������������������������������������������������� 239 Hands-On Activities for Organizing Array’s Data Elements and Accessing Them Efficiently ������������������������������������������������������������������������������������������������������������������� 242 Efficient and Reliable Ways to Access Structures Using Pointers ��������������������������������������������� 246 Basic Pointers Accessing Ways for Structures �������������������������������������������������������������������� 247 Advanced Pointers Accessing Ways for Structures ������������������������������������������������������������� 249 Hands-On Activity ���������������������������������������������������������������������������������������������������������������� 250 Pointers and Functions for Powerful Programming Techniques ����������������������������������������������� 255 Pointers to a Variety of Functions ���������������������������������������������������������������������������������������� 256 C Ways for Polymorphism ���������������������������������������������������������������������������������������������������� 261 Hands-On Activity ���������������������������������������������������������������������������������������������������������������� 262 Summary����������������������������������������������������������������������������������������������������������������������������������� 267 Practice Tasks ��������������������������������������������������������������������������������������������������������������������������� 267 Table of ConTenTs
viii Chapter 5: C Programming for Memory Management ������������������������������������������ 269 Introduction to Dynamic Memory Management ������������������������������������������������������������������������ 270 Importance of Dynamic Memory Management ������������������������������������������������������������������� 270 Important C System Calls for Memory Management ����������������������������������������������������������� 271 Important C System Calls for Memory Management ���������������������������������������������������������������� 274 C Library Functions for Basic Dynamic Memory Management ������������������������������������������� 274 C System Calls for Extending Memory Blocks Dynamically ������������������������������������������������ 277 C System Calls for Handling Multiple Blocks of Memory Allocation ������������������������������������ 279 Error Handling Programming Techniques for Memory Management ���������������������������������������� 281 Best Dynamic Memory Management Practices ������������������������������������������������������������������� 281 Memory Error Handling Techniques Using Valgrind ������������������������������������������������������������� 285 Hands-On Activity Using Valgrind Tools ������������������������������������������������������������������������������� 288 Setting Up Memory Buffers and Accessing Them in a Reliable Manner ����������������������������������� 293 Hands-On Activity-1 ������������������������������������������������������������������������������������������������������������� 294 Hands-On Activity-2 ������������������������������������������������������������������������������������������������������������� 300 Hands-On Activity-3 ������������������������������������������������������������������������������������������������������������� 306 Summary����������������������������������������������������������������������������������������������������������������������������������� 312 Practice Tasks ��������������������������������������������������������������������������������������������������������������������������� 312 Chapter 6: Process and Thread Management Tasks for C Programmers ������������� 315 Introduction to Processes and Threads ������������������������������������������������������������������������������������� 316 Process Management Basic Activities Using Fork ��������������������������������������������������������������� 317 Thread Management Basic Activities ���������������������������������������������������������������������������������� 319 Explore the Power of Process Management Using C Programming ����������������������������������������� 324 Developers’ Role and Activities in Process Management ���������������������������������������������������� 324 Creating a Specific Number of Processes ��������������������������������������������������������������������������� 327 Control the Multiple Processes Execution Order ����������������������������������������������������������������� 331 Create N Processes and Load Them with Executable Images ��������������������������������������������� 335 Safe and Reliable Programming Ways for Process Management ��������������������������������������������� 340 Importance of Parent and Child Processes Exit Order ��������������������������������������������������������� 342 Handle Carefully Data Sharing Activities Between Parent and Child Processes ����������������� 345 Table of ConTenTs
ix Reliable Ways of Executing a New Process in a Child Process ������������������������������������������� 354 Importance of Interrupt Handling in Process Management ������������������������������������������������� 357 Explore Power of Threads Management Using C Programming ����������������������������������������������� 363 Developer’s Role in Threads Management �������������������������������������������������������������������������� 363 Hands-On Activity-1 ������������������������������������������������������������������������������������������������������������� 378 Hands-On Activity-2 ������������������������������������������������������������������������������������������������������������� 383 Safe and Reliable Programming Ways for Threads Management ��������������������������������������������� 387 Improve the Performance of a Multithreaded Application ��������������������������������������������������� 387 Multithreading Application Performance Tuning ������������������������������������������������������������������ 388 Quickly Identify and Handle Threads Synchronization Issues ��������������������������������������������� 396 Summary����������������������������������������������������������������������������������������������������������������������������������� 401 Practice Tasks ��������������������������������������������������������������������������������������������������������������������������� 402 Chapter 7: Handle Interprocess Activities Using C Programming ������������������������ 405 Essential Linux Interprocess Communication (IPC) Approaches ����������������������������������������������� 406 Linux Basic Services for File Handling �������������������������������������������������������������������������������� 407 Importance of dup and dup2 ����������������������������������������������������������������������������������������������� 408 PIPEs ������������������������������������������������������������������������������������������������������������������������������������ 409 FIFO ������������������������������������������������������������������������������������������������������������������������������������� 410 Message Queues ����������������������������������������������������������������������������������������������������������������� 412 Shared Memory ������������������������������������������������������������������������������������������������������������������� 414 Semaphores ������������������������������������������������������������������������������������������������������������������������ 416 Explore C Programming and Linux IPC Tools for IPC Management ������������������������������������������� 418 Usage of PIPEs in C�������������������������������������������������������������������������������������������������������������� 418 Usage of FIFO in C ��������������������������������������������������������������������������������������������������������������� 422 Usage of Message Queues in C ������������������������������������������������������������������������������������������� 427 Usage of Shared Memory in C ��������������������������������������������������������������������������������������������� 434 Explore C Ways to Implement Service Chaining and Asynchronous Programming ������������������� 440 Hands-On Activity-1 ������������������������������������������������������������������������������������������������������������� 441 Hands-On Activity-2 ������������������������������������������������������������������������������������������������������������� 445 Hands-On Activity-3 ������������������������������������������������������������������������������������������������������������� 451 Table of ConTenTs
x Essential IPC Synchronization Handling Tools ��������������������������������������������������������������������������� 457 Semaphores ������������������������������������������������������������������������������������������������������������������������ 458 Usage of Semaphore in C ���������������������������������������������������������������������������������������������������� 459 Hands-On Activity-1 ������������������������������������������������������������������������������������������������������������� 461 Hands-On Activity-2 ������������������������������������������������������������������������������������������������������������� 466 Summary����������������������������������������������������������������������������������������������������������������������������������� 471 Practice Tasks ��������������������������������������������������������������������������������������������������������������������������� 472 Chapter 8: Essential Network Socket Programming Skills ����������������������������������� 473 Quick Introduction to TCP/IP Stack and Network Applications�������������������������������������������������� 474 TCP/IP Stack ������������������������������������������������������������������������������������������������������������������������ 475 TCP/IP Stack and Network Interactions ������������������������������������������������������������������������������� 477 TCP Socket Programming ��������������������������������������������������������������������������������������������������������� 481 TCP Rules ���������������������������������������������������������������������������������������������������������������������������� 482 TCP Socket Programming Constructs ���������������������������������������������������������������������������������� 486 TCP Socket Programming Practice �������������������������������������������������������������������������������������� 501 UDP Socket Programming ��������������������������������������������������������������������������������������������������������� 515 UDP Socket Programming in C �������������������������������������������������������������������������������������������� 517 UDP Socket Programming in C �������������������������������������������������������������������������������������������� 523 Hands-On Activity-1 ������������������������������������������������������������������������������������������������������������� 529 C Programming Ways for Monitoring and Inspecting TCP/UDP Applications Traffic ������������������ 539 Packet Monitoring and Filtering Activities ��������������������������������������������������������������������������� 539 Hands-On Activity-1 ������������������������������������������������������������������������������������������������������������� 542 Hands-On Activity-2 ������������������������������������������������������������������������������������������������������������� 547 Summary����������������������������������������������������������������������������������������������������������������������������������� 551 Practice Tasks ��������������������������������������������������������������������������������������������������������������������������� 551 Chapter 9: Essential Advanced Socket Programming Ways Using C Sockets ������ 553 Important Socket Programming Approaches ���������������������������������������������������������������������������� 554 Multiprocessing and Multithreading ������������������������������������������������������������������������������������ 556 Must-Know Socket Options ������������������������������������������������������������������������������������������������� 559 Non-blocking Socket Programming������������������������������������������������������������������������������������� 564 Table of ConTenTs
xi Non-blocking Ways of Socket Programming ����������������������������������������������������������������������������� 565 Usage of fcntl and select ����������������������������������������������������������������������������������������������������� 565 Hands-On Activity-1 ������������������������������������������������������������������������������������������������������������� 568 Hands-On Activity-2 ������������������������������������������������������������������������������������������������������������� 578 Handle TCP Client-Server Performance and Reliability Issues ������������������������������������������������� 584 The Reliable TCP Server and Client ������������������������������������������������������������������������������������� 587 Hands-On Activity-1 ������������������������������������������������������������������������������������������������������������� 597 Hands-On Activity-2 ������������������������������������������������������������������������������������������������������������� 599 Hands-On Activity-3 ������������������������������������������������������������������������������������������������������������� 602 Handle UDP Client-Server Performance and Reliability Issues ������������������������������������������������� 604 Hands-On Activity-1 ������������������������������������������������������������������������������������������������������������� 605 Hands-On Activity-2 ������������������������������������������������������������������������������������������������������������� 612 Summary����������������������������������������������������������������������������������������������������������������������������������� 621 Practice Tasks ��������������������������������������������������������������������������������������������������������������������������� 622 Chapter 10: Learn C Programming Skills for Virtualization ��������������������������������� 623 Introduction to Linux Namespaces ������������������������������������������������������������������������������������������� 624 Linux Namespaces �������������������������������������������������������������������������������������������������������������� 625 Linux cgroups ���������������������������������������������������������������������������������������������������������������������� 627 Learn How to Program Linux Namespaces and cgroups ���������������������������������������������������������� 630 Detach a Process from Inherited Namespaces ������������������������������������������������������������������� 630 Attach a Process with Existing Namespaces����������������������������������������������������������������������� 636 Clone New Processes with Suitable Namespaces �������������������������������������������������������������� 643 Learn Setting Up and Using Control Groups ������������������������������������������������������������������������ 652 Experiment with Process and Memory Namespaces ���������������������������������������������������������������� 655 Hands-On Activity-1 ������������������������������������������������������������������������������������������������������������� 656 Hands-On Activity-2 ������������������������������������������������������������������������������������������������������������� 661 Hands-On Activity-3 ������������������������������������������������������������������������������������������������������������� 666 Hands-On Activity-4 ������������������������������������������������������������������������������������������������������������� 671 Hands-On Activity-5 ������������������������������������������������������������������������������������������������������������� 674 Table of ConTenTs
xii Experiment with Networking Namespaces ������������������������������������������������������������������������������� 679 Learn Setting Up Network Namespaces ������������������������������������������������������������������������������ 679 Various Virtual Networks Setups ����������������������������������������������������������������������������������������� 682 Hands-On Activity-1 ������������������������������������������������������������������������������������������������������������� 688 Hands-On Activity-2 ������������������������������������������������������������������������������������������������������������� 691 Hands-On Activity-3 ������������������������������������������������������������������������������������������������������������� 694 Summary����������������������������������������������������������������������������������������������������������������������������������� 699 Index ��������������������������������������������������������������������������������������������������������������������� 701 Table of ConTenTs
xiii About the Author Dr. Anil Kumar Rangisetti received his PhD in the field of computer science and engineering from IIT Hyderabad, India. He has 13 years of teaching and research experience in computer science and engineering. During his career, he worked at prestigious Indian institutions, such as IIIT Dharwad, SRM-AP, and GMR, and worked at software development and research labs such as ARICENT and IRL-Delhi. Currently he is working as assistant professor in the Department of CSE, IIITDM, Kurnool. He trained many students in programming languages and in the use of advanced simulators (NS-3), Docker, and networking tools for researching and developing applications at his workplaces. He guided a significant number of undergraduate and postgraduate students for project works. Broadly, his research interests include Wi-Fi technologies, next-generation mobile networks, SDN, NFV, and cloud computing. He authored a number of novel research publications with IEEE, Springer, Elsevier, and Wiley in the field of a variety of networking technologies such as LTE, SDN and NFV, and Wi-Fi technologies. He authored various practical books related to network simulations, future networking technologies, and programming languages. He brings with him academic and professional experience, which includes time spent at Aricent and the IBM research lab. Additionally, he enjoys writing and reviewing books on systems and networking technologies, mobile and wireless networks, cloud computing technologies, and programming languages.
xv German Gonzalez-Morris is a polyglot software architect/ engineer with 20+ years in the field, with knowledge in Java, SpringBoot, C/C++, Julia, Python, Haskell, and Javascript, among others. He works with cloud (architecture) web- distributed applications and microservices. German loves math puzzles (including reading Knuth, and is proud of solving some of Don’s puzzles), swimming, and table tennis. Also, he has reviewed several books, including books on application containers (WebLogic) and programming languages (C, Java, Spring, Python, Haskell, Typescript, WebAssembly, Math for coders, regexp, Julia, data structures and algorithms, and Kafka).    About the Technical Reviewer
xvii Acknowledgments First of all, I would like to thank Apress for believing my book idea and giving me this wonderful opportunity. I would especially like to thank Melissa Duffy for keenly going through the book proposal and suggesting to me how to make the book proposal interesting and perfect. Melissa’s support and encouragement throughout the book writing process has been wonderful. All of Melissa’s suggestions helped in improving the quality of the book’s content. I would like to thank Krishnan Sathyamurthy for his constant support in the entire review and finalization of the book’s content. Krishnan’s timely help and support helped me to complete all works in time. A big thanks to the technical reviewer of the book for his valuable time and suggestions in all hands-on activities and technical concepts of the book. His keen observations helped me a lot in correcting all kinds of errors and incorporating necessary topics to improve the quality of the book tremendously. I would like to thank each and every member of the Apress team for supporting me in writing this wonderful book and completing it successfully and happily. I would love to work with the Apress team again and again. My heartfelt thanks to all my students for their interest in attending my lectures and working with me. All my students’ curiosity, comments, and suggestions helped me to write this wonderful book. Finally, I would like to thank all my family members, friends, and colleagues for their love and support always.
xix Introduction C programming is known for developing systems software (operating systems, databases, network protocol stack, and virtualization technologies) and applications by efficiently utilizing system computational resources. In this book you will be exploring C programming key skills such as handling functions, arrays, strings, unions, pointers, and memory. While learning these key skills, you will be exploring important runtime error handling techniques and best practices to implement reliable and efficient C programs. It is necessary to develop runtime errors and performance handling code in your C applications before deploying them in the runtime environment. Otherwise your programs/applications can crash the system and/or be damaged by other malicious or error-prone applications. In order to help you in thinking of a runtime environment and handling possible issues, this book introduces and discusses how to use important open- source Linux tools (gcc, gdb, gcov, valgrind) for compilation, linking, debugging, code coverage, and handling memory leaks. This book’s chapters are organized in the following logical manner for easy and quick ways of learning complex concepts. In Chapters 1, 2, and 3, we discuss basic computer system architecture and essential operating systems concepts for implementing reliable and efficient C code. Then, you will go through C programming essential skills such as handling arrays, strings, unions, pointers, and memory management using open-source Linux tools (gcc, gdb, gcov, valgrind). In Chapters 4 and 5, you will be dedicatedly practicing runtime error handling and best practices in terms of Pointers usages, dynamic memory allocation handling, and accessing arrays, structures, strings, and buffers. Later you will learn the importance of these concepts while implementing system and network programming. Later in Chapters 6 and 7, you will explore the power of C programming in terms of system programming and high-performance computing; specifically, you will learn process and thread management for multitasking or multiprocessing through essential system calls. Mainly, you will learn programmer responsibilities in terms of process management tasks such as creating multiple processes, management of process segments, waiting for processes, termination activities, inter-process communication,
xx synchronization issues, and handling exceptional conditions. These are necessary skills for handling external inputs and runtime errors and offering reliable deployment opportunities for running C applications with multiple processes or threads. Next, in Chapters 8 and 9, you will explore the power of C socket programming and important system calls to implement TCP/UDP network applications. You will start with a quick introduction of the TCP/IP stack and applications. Specifically, you will learn flexible and error-free ways for handling socket buffers, packets, and fields accessed through C dynamic memory, strings, and pointers concepts. Moreover, we will also discuss essential programming ways (blocking and non-blocking), essential socket options for handling network server/client applications, runtime errors, and performance issues. Finally, in Chapter 10, you will learn Linux namespaces and their role in virtualization. Specifically, you will learn C programming ways and system calls for handling Linux namespaces and control groups. You will be experimenting with important Linux namespaces such as process, memory, and networking to learn how the popular lightweight virtualization solutions are working. This chapter will help you to explore the importance of virtualization in cloud environments. InTroduCTIon
1 © Dr Anil Kumar Rangisetti 2026 Dr A. K. Rangisetti, C Programming for System, Network, and Cloud Engineers, https://doi.org/10.1007/979-8-8688-1805-9_1 CHAPTER 1 Basic Computer System Architecture and Essential Operating System Concepts Learning about computer system architecture is essential for software developers to implement performance meeting optimized code for system software or applications. Mainly, insights into the underlying system architecture, its components (CPU, memory, cache, registers, I/O devices, system buses), and their interconnections are helpful to tune the application performance metrics such as throughput, latency, reliability, scalability, and security. For instance, knowing details of computer memory hierarchy and organization helps developers to implement suitable codes for minimizing memory access latencies and utilizing the memory optimally. Similarly, learning about the processor architecture in terms of the number of cores and their interconnection helps in writing suitable computational load distribution codes for maximizing CPU core utilization and minimizing communication latencies. On the other hand, an important system software called operating system (OS) runs over a computer system for simplifying its usage by end users and managing the system’s computational, memory, and input/output (IO) resources. OS helps software developers to a greater extent for developing applications and software-specific development tasks without worrying about the underlying system architecture. However, developers must know OS powers, responsibilities, and how to interact with the OS to develop secure and performance-optimized code. For instance, ignoring how the OS is handling a program execution and managing its system memory can lead to access violations and security
2 loopholes in software. In this book, we use Linux OS as a platform for practicing C programming. We discuss necessary Linux OS concepts to help developers to perform their programming activities. In addition to computer system architecture and OS, system developers must know how to utilize the system software tools such as compilers, debuggers, loaders, and linkers to simplify the software development, debugging, and deployment activities. In this chapter, we discuss the following topics to help C programmers learn and develop C applications and handle performance issues: • Introduction to basic computer system architecture • Operating system responsibilities • Importance of compiler, linker, and loader • Runtime environment of a process • C Programmer powers and responsibilities Basic Computer System Architecture The heart of any computer system is its central processing unit (CPU). It is interconnected with other important components to process software application inputs, perform computations, and store results. Chapter 1 BasiC Computer system arChiteCture and essential operating system ConCepts
3 Figure 1-1. Today’s general CPU architecture and its internal components Let’s inspect the details of today’s standard CPU architecture. From Figure 1-1, check the major components of a CPU architecture. CPU Architecture Today’s CPU has the following important components: • Multiple CPU cores with internal caches (L1, L2, and L3) • Floating point unit (FPU) • Memory management unit (MMU) • System buses for interconnecting memory and input/output (IO) devices Let’s check these internal component details for better programming. The CPU Cores: Today’s CPU is equipped with multiple CPU cores (refer to Figure 1-1), and each CPU core can support multiple hardware threads to improve the system processing power in terms of performing the parallel tasks. Most of the modern CPUs, such as Intel’s CPU support two hardware-level threads per core through hyper- Chapter 1 BasiC Computer system arChiteCture and essential operating system ConCepts