CS015605-Operating System #2

Hyung Jun·2021년 3월 7일
0

CS

목록 보기
2/2
post-thumbnail

이 글의 내용은 국민대학교 황현태 교수님 CS015605 운영체제 수업의 필기 노트입니다.

OperatingSystem #2 week

Process

Informally, the defintion of a process is a running program. The program itself is a lifeless thing. It just sits there on the disk, a bunch of instructions(and maybe some static data), waiting to spring into action. It is the operating system that takes these bytes and gets them running, transforming the program into something useful.

By virtualising the CPU, the OS runs one process then stopping it and running another, and so forth. The OS can promote the illusion tha tmany virtual CPUs exist when in fact there is only one physical CPU (or a few).

Time Sharing

Time Sharing is a basic technique used by an OS to share a resource.
Time sharing of the CPU allows users to run as many concurrent processes as they would like; the pothential cost is performance, as each will run more slowly if the CPU(s) must be shared.

Mechanisms

To implement virtualisation of the CPU, the OS will need both some low-level machinery and some high-level intelligence. The low-level machinery is called 'Mechanisms'. Mechanisms are low-level methods or protocols that implement a needed piece of functionality. For example it implements a context switch, which gives the OS the ability to stop running one program and start running another on a given CPU.
On top of these mechanisms resides some of the intelligence in the OS, in the form of policies.
Pollicies are algorithms for making some kind of decision within the OS. For example, given a number of possible programs to run on a CPU, which program should the OS run? A scheduling policy in the OS will make this decision.

Process API

  • Create
    An OS must include some method to create new processes. When you type a command into the shell, or double-click on an application icon, the OS is invoked to create a new process to run the program you have indicated.
  • Destroy
    As there is an interface for process createion, system also provide an interface to destroy processes forcefully. Of course, many processes will run and just exit by themselves when complete; when they don't, however, the user may wish to kill them, and thus an interface to halt a runaway process is quite useful.
  • Wait
    Sometimes it is useful to wait for a process to stop running; thus some kind of waiting interface is often provided.
  • Miscellaneous Control
    Other than killing or waiting for a process, these are sometimes other controls that are possible. For example, most operating systems provide some kind of method to suspend a process and then resume it.
  • Status
    There are usually interfaces to get some status information about a process as well, such as how long it has run for, or what state it is in.

Process Creation


Loading From Program To Process
The first thing that the OS must do to run a program is to load its code and any static data(e.g., initialised variables) into memory, into the address space of the process.
Programs initally reside on disk (or SSDs) in some kind of executable format.
In early operating systems, the loading process is done eagerly, i.e., all at once before running the program; modern OSes perform the process lazily, i.e., by loading pieces of code or data only as they are needed during program execution.

Once the code and static data are loaded into memory, there are a few other things the OS needs to do before running the process. Some memory must be allocated for program's stack. As we know, C programs use the stack for local variables, function parameters, and return addresses. The OS will also likely initialise the stack with arguments; specifically, it will fill in the parameters to the main() function.
The OS may also allocate some memory for the program's heap. In C programs, the heap is used for explicitly requested dynamically-allocated data; programs request such space by calling malloc() and free it explicitly by calling free(). The heap is needed for data structures such as linked list, hash tables, trees, and other interesting data structures. The heap will be small at first; as the program runs, and requests more memory via the malloc() library API, the OS may get involoved and allocated more memory to the process to help satisfy such calls.
The OS will also do some other initialisation tasks, particularly as realated to I/O. For example, in UNIX systems, each process by default has three open file descriptors, for standard input, output, and error.

Process States

  • Running: In the running state, a process is running on a processor. This means it is executing instructions.
  • Ready: In the ready state, a process is ready to run but for some reason the OS has chosen not to run it at this given moment.
  • Blocked: In the blocked state, a process has performed some kind of operation that makes it not ready to run until some other event takes places.
profile
Keep Learning👨🏻‍💻

0개의 댓글