5 DERECHA
linux 3 본문
1. The basics of operating system
(1) Operating System
An operating system (OS) is a software program that manages computer hardware and software resources and provides common services for computer programs. The OS is responsible for providing an interface between the user and the hardware, controlling and coordinating the use of the computer's resources, and providing a platform for running applications.
One of the primary functions of an operating system is process management, which involves managing the execution of programs and processes on the system. The OS is responsible for creating and terminating processes, scheduling them for execution, and providing inter-process communication mechanisms.
Another important function of an OS is memory management, which involves managing the allocation and deallocation of memory resources on the system. The OS is responsible for managing the virtual memory space of each process and providing mechanisms for sharing memory between processes.
File management is another important function of an operating system, which involves managing the creation, deletion, and manipulation of files and directories on the system. The OS is responsible for providing a file system that allows users to access and manipulate files and directories on the system.
When managing these functions in user mode, the operating system can only perform them through a system call, which is a mechanism that allows user programs to request services from the OS. When a system call is made, the CPU switches from user mode to kernel mode, which is a privileged mode of operation that provides access to the hardware and system resources. Once the system call is complete, the CPU switches back to user mode.
Kernel mode is typically implemented as a ring 0(x86) or exception level 3(ARM), which is the highest level of privilege in a modern operating system. User mode, on the other hand, is typically implemented as a ring 3(x86) or exception level 0(ARM), which is the lowest level of privilege.
A service daemon is an application program that runs in the background and provides services to other programs on the system. Service daemons are typically used in server environments to provide services such as printing, file sharing, and database access.
(1) Process & IPC & Thread
Process: In computing, a process is an instance of a computer program that is being executed. It is a unit of work that is managed independently by the operating system and contains program code, data, and other resources required to execute the program. A process may contain multiple threads, and each process has its own memory space, file descriptors, and other resources.
Interprocess Communication (IPC): Interprocess communication refers to the mechanisms that processes use to exchange data and information with each other. IPC is important for implementing distributed systems, where different processes or machines need to communicate with each other to accomplish a task. IPC mechanisms include shared memory, message passing, pipes, and sockets.
Thread: A thread is a basic unit of CPU utilization, representing a single sequence of execution within a process. Threads allow a process to execute multiple tasks concurrently and are commonly used in modern operating systems to implement multitasking. Each thread has its own stack, program counter, and set of registers, but shares the same memory space as the parent process. Threads can communicate with each other via shared memory or IPC mechanisms.
(2) Context Switching
Scheduling: In an operating system, scheduling refers to the process of determining which process or thread should execute next on the CPU. The scheduler is responsible for selecting the next process or thread to run based on a scheduling algorithm, which can be preemptive or non-preemptive. Preemptive scheduling allows the scheduler to interrupt the currently running process or thread and allocate the CPU to a higher-priority process or thread, while non-preemptive scheduling only allows the currently running process or thread to release the CPU voluntarily.
Context Switching: Context switching is the process of storing the context or state of a process or thread that is currently running on the CPU, so that it can be resumed later, and restoring the context of a different process or thread so that it can run on the CPU. Context switching is necessary for preemptive scheduling, where the scheduler may need to interrupt the currently running process or thread to allow a higher-priority process or thread to run. Context switching is a relatively expensive operation, as it involves saving and restoring the state of the CPU, memory, and other resources associated with the process or thread.
(3) Interrupts
Interrupts: An interrupt is a signal that is sent to the processor by a hardware device or software process, indicating that some event has occurred that requires the processor's attention. Interrupts can be classified into two types: hardware interrupts and software interrupts. Hardware interrupts are generated by hardware devices, such as keyboard, mouse, or network card, to request the CPU's attention. Software interrupts, also known as system calls, are generated by user processes to request services from the operating system, such as reading or writing to a file.
(4) Device Driver
<예시>
2. System calls
사용자 모드에서는 메모리 접근이나 함후 호출이 불가능하니, 시스템 콜을 통해서 사용.
1) 응용프로그램은 시스템 콜 번호, 파라미터와 함께 시스템 콜을 실행
2) 시스템 콜은 현재 모드를 커널 모드로 전환
3) 커널을 시스템 콜 번호를 보고 해당 함수 호출
<시스템 콜 예시>
https://bit.ly/3D9XCOz
#코멘토 #코멘토실무PT #실무PT후기