This report promises to provide a profound insight into the research, design, and deployment process of an application utilizing Shared Memory.. 1 Reason for choosing the topic We have c
Trang 1UNIVERSITY OF INFORMATION AND TECHNOLOGY VIETNAM
Phan Van Xuat 21IT256
Trang 2UNIVERSITY OF INFORMATION AND TECHNOLOGY VIETNAM
Phan Van Xuat 21IT256
Class : System Programming(2)
Da Nang, November 19, 2023
Trang 3To research this topic, our team received significant support and assistance fromour supervising lecturer, Dr.Hoang Huu Duc With deep and sincere gratitude, wewould like to express our appreciation to him and all our colleagues who workedtogether, provided help, and conducted research throughout the project Given theconstraints of time and limited experience, this report may not be free fromshortcomings We eagerly anticipate guidance and input from our lecturer
Our team sincerely thanks you!
Trang 4
DIVISION OF WORK
Trang 51.1 Overview of system programming 4
1.2 General information about IPC 5
1.4 Introducing shared memory 8
1.4.1 Concept of shared memory 8
1.4.2 Shared Memory works 9
1.5 Overview of key technologies 9
1.5.2 The C programming language 11 CHAPTER 2: DESIGN AND IMPLEMENTATION 13
2.1 Shared memory application 13
2.1.1 Multi-process and multi-threaded system 13
Trang 62.2.4 Access coordination 15
2.2.5 Disconnect and release memory 15
2.3 Advantages and disadvantages of shared memory 15
2.3.1 Advantages of Shared Memory 15
Trang 7LIST OF IMAGES
Picture 1 1 System programming 4
Picture 1 2 Inter-Process Communication(IPC) 5
Picture 1 3 Shared Memory 8
Picture 1 4 VMware 9
Picture 1 5 The C programming language 10
Picture 2 1 Shared memory application 12
Picture 3 1 Code check phone number 16
Picture 3 2 Run Code check phone number 16
Picture 3 3 Code check email 17
Picture 3 4 Run Code check email 17
Picture 3 5 Code check read file 18
Picture 3 6 Code displays the contact list 18
Picture 3 7 Run Code displays the contact list 18
Picture 3 8 Code add people to the list 19
Picture 3 9 Run code add people to the list 19
Picture 3 10 Code to export contacts to file 20
Picture 3 11 Run code to export contacts to file 20
Picture 3 12 Code edit people in contacts 21
Picture 3 13 Run code edit people in contacts 21
Picture 3 14 Code delete people from contacts 22
Picture 3 15 Run code delete people from contacts 22
Trang 8In today's technology-driven world, optimizing interactions among system
components plays a crucial role, with Inter Process Communication (IPC) becoming
an indispensable aspect in the field of system programming
We chose to delve into the study and implementation of Shared Memory, a powerful IPC method, to achieve flexibility and high performance in transmitting information between processes This report promises to provide a profound insight into the research, design, and deployment process of an application utilizing Shared Memory
We anticipate that by sharing our experiences and knowledge gained, this report willcontribute to enriching the understanding within the system programming
community We hope that the outcomes of this project will help readers gain a clearer understanding of the vital role IPC and Shared Memory play in constructing efficient software systems
1 Reason for choosing the topic
We have chosen the topic "Inter Process Communication - Shared Memory" for several significant reasons In today's technology-driven world, efficient interaction among system components plays a crucial role, and Inter Process Communication (IPC) becomes an indispensable factor The decision to research and implement Shared Memory is motivated by its flexibility and high performance in transmitting information between processes This promises to provide a profound insight into the research and deployment process of applications, contributing to the enrichment of knowledge within the system programming community We anticipate that the outcomes of this project will help readers gain a clearer understanding of the crucial role IPC and Shared Memory play in constructing efficient software systems
2 Topic Objectives
Develop a solid understanding of the concept of Shared Memory and other IPC methods
Grasp the mechanism and pros/cons of Shared Memory
Implement a demo Application Using Shared Memory
Learn and apply analysis, testing, and debugging methods and tools during declarative development and application demos
Evaluate application performance and stability
Present the results and experiences from the implementation and demo
process in a project report, including analysis, experimental results and
comments
3 Direction of the topic
The direction of the topic "Implement and Demo for Sockets in IPC" in the project report can be implemented according to the following chapters:
Chapter 1: INTRODUCTION
Trang 9 Chapter 2: DESIGN AND IMPLEMENTATION
Chapter 3: DEMO
4 Research subjects
The topic "Inter Process Communication Shared Memory" may be suitable for university students, software developers, researchers and anyone interested in the process of exchanging information between processes
5 Research scope
Inter Process Communication (IPC):
- Investigate fundamental aspects of various IPC methods
- Compare and evaluate the effectiveness of IPC in facilitating interaction between processes
Real-world Application Deployment:
- Develop a practical application utilizing Shared Memory for information exchange between processes
- Evaluate performance and optimize within the context of real-world
application usage
Integration of Feature Expansion and Scalability:
- Research and implement additional features to enhance the application's functionality
- Assess the application's scalability on large systems with multiple processes
Performance Evaluation and Comparison with Other IPC Methods:
- Conduct a performance evaluation of the application using Shared Memory and compare it with other IPC methods
Results Analysis and Discussion:
- Analyze the achieved results from implementation and evaluation
- Discuss limitations, challenges, and the significance of the findings
Trang 10CHAPTER 1:INTRODUCTION
1.1 Overview of system programming
1.1.1 System programming concepts
Picture 1 1 System programming
System programming is the activity of developing system software Firstly, it
highlights the distinct nature of system programs when compared to application programming, where application programming aims to create software that provides services to users (e.g., word processors), whereas system programmers focus on producing software that delivers services to computer hardware (e.g., disk
defragmentation software) It also necessitates a greater awareness of hardware considerations
1.1.2 System programming overview
More special points in system programming:
System programmers will bear the responsibilities related to hardware and certain attributes of programs running on that system, and they will often leverage those attributes (for example, by using an algorithm known to be effective when employed with specific hardware)
Typically, a low-level programming language or assembly language is
employed for the following reasons:
- Can operate in resource-constrained environments
- Highly efficient and capable of performing close to the hardware
- Has a minimal or no runtime library
Trang 11- Allows direct and "raw" control through memory access and control flow.
- Enables programmers to write portions of the program directly in assembly language
System programmers differ significantly from application programmers who
specialize in one domain or another
In system programming, there are often limited programming tools available The use of automatic garbage collection is not common, and debugging can be
challenging at times Implemented libraries, if available at all, are often less robust than those in more common programming languages, leading to fewer error checks Due to these limitations, consoles and logging are frequently employed, and
operating systems may extensively utilize hierarchical logging systems
System programmers perform specific tasks within an operating system and network operations, such as implementing paging (virtual memory) or a device driver for an operating system
1.2 General information about IPC
IPC stands for "Inter-Process Communication" in the field of information technologyand computer programming IPC is the way different processes on a computersystem or within a network can communicate, exchange information, and interactwith each other This enables different processes to perform distinct tasks andcollaborate to accomplish larger objectives or share data and resources with eachother
Trang 12Picture 1 2 Inter-Process Communication(IPC)
1.3 Main methods of IPC
1.3.1 Socket
- TCP/IP Socket utilizes the Transmission Control Protocol (TCP) to establish
a reliable connection between two endpoints The endpoints can be two processes on the same computer or two different computers on a network TCP ensures data integrity and correct sequencing, providing mechanisms such as error control, flow control, and authentication
- UDP Socket uses the User Datagram Protocol (UDP), a less reliable protocol compared to TCP UDP does not guarantee data integrity and sequencing This may be suitable for applications that require fast data transmission and can tolerate data loss, such as live streaming or online gaming
- By using sockets, applications can establish network connections and
send/receive data over the network through TCP/IP or UDP protocols An application can run as a server, listening for connection requests from other applications and handling them Alternatively, it can run as a client,
establishing a connection to an existing server and transmitting data over the network
- With TCP/IP or UDP sockets, different processes or computers can
communicate and share data over the network or on the same computer
Trang 131.3.2 Message Queues
- Use queues to allow processes to send and receive text messages or structureddata Message queues can be utilized for sending and receiving simple text messages or structured data Simple text messages are often used for control communication or notifications between processes, while structured data can include records, complex data structures, or serialized objects
- Processes can send messages to a queue at any time, and the receiving processcan dequeue messages in the order they were placed in the queue This creates
an asynchronous communication between processes, allowing them to operateindependently and without dependencies on each other Message queues are acommon mechanism for IPC in multiprocess or distributed systems They enable processes to communicate safely and efficiently, ensuring data
integrity during communication
1.3.3 Shared Memory
- Is a mechanism in the operating system that allows processes to share a portion of common memory Instead of copying data back and forth between processes, they can directly access the same memory region This speeds up data access and reduces overhead associated with data copying
1.3.4 Pipes
- Are a mechanism in the operating system used to transmit data between parent and child processes in a process communication model Pipes are created by connecting the output of one process to the input of another
process, forming a one-way communication channel
1.3.5 RPC (Remote Procedure Call)
- Is a protocol and programming model that allows calling functions or
methods from a remote process in a manner similar to calling functions withinthe same process RPC enables applications running on different computers in
a network to interact and communicate with each other through remote
function calls
1.3.6 Synchronization mechanism
- Are used to ensure consistency and safety in the execution of concurrent processes Mechanisms such as semaphores, mutexes, and conditions are essential tools in building synchronization solutions
Trang 14operation Semaphores enable control over concurrent access to resources andhelp avoid issues such as conflicts and starvation.
- Mutex (Mutual Exclusion): Mutex is a synchronization mechanism used to ensure that only one process can access a shared resource at a time Mutex is often employed to protect sections of code called a "critical section," where shared data may be subject to conflicts A process wishing to access the critical section must invoke the "lock" operation on the mutex before
performing operations on shared data and call the "unlock" operation after completion If the mutex has already been locked by another process, the current process will be blocked until the mutex is released Mutex helps ensure consistency and prevent conflicts when accessing shared data
- Condition: Condition is a synchronization mechanism used to manage waitingand signaling between processes Conditions are often employed in
synchronization scenarios following the "producer-consumer" model or similar scenarios A process can invoke the "wait" operation on a condition to wait for a specific condition to be met When the condition is met, another process can send a signal through the "signal" or "broadcast" operation to notify the waiting processes Conditions help manage waiting and signaling between processes and avoid issues such as indefinite waiting or false wake-ups
1.4 Introducing shared memory
1.4.1 Concept of shared memory
- Shared Memory is a mechanism that allows multiple processes or threads in a computer system to access and share the same physical memory area (RAM)
to exchange data In shared memory, processes can read and write data to this shared memory area, allowing them to interact and communicate quickly and efficiently
Picture 1 3 Shared Memory
Trang 151.4.2 Shared Memory works
- Create and Attach: One process, often the "creator" process, creates a shared memory region through the system API (e.g., shmget in Unix) Another process, typically the "attacher" process, uses the same key to access that shared memory region
- Access Data: Once the shared memory region is created and attached,
processes can directly access it like any other memory region using pointers
needed
- Remove Memory Region: In some cases, the creating process may decide to remove the shared memory region after it's no longer in use This ensures that the shared memory region won't persist after all processes have finished usingit
1.5 Overview of key technologies
1.5.1 Vmware
VMware is a virtualization software system that enables users to run multiple
operating systems (OS) on the same computer It allows users to install an operating system within a virtual environment while maintaining the original host operating system on the computer
Trang 16Picture 1 4 VMware
With VMware, users can run multiple different operating systems on the same computer without the need to reinstall each time they want to switch to a different operating system VMware also has the ability to share resources among virtual operating systems, helping to save resources and increase system performance
VMware was founded in 1998 by Diane Greene, Mendel Rosenblum, Scott Devine, and Edward Wang It is a multinational technology company with its headquarters inPalo Alto, California, USA VMware is one of the leading virtualization software companies globally, offering various products and services related to system
virtualization, including VMware Workstation, VMware Fusion, and VMware vSphere
Main function of Vmware:
Create and manage virtual machines
- VMware provides tools and solutions that allow users to create and manage virtual machines on their computers These virtual machines resemble actual computers, allowing users to run operating systems and other applications on them
Manage computers in a corporate environment
- The tool will have features to help IT administrators manage and monitor computers in a business environment, helping administrators easily manage and maintain computer systems
Synchronize computer environments