Clever Geek Handbook
📜 ⬆️ ⬇️

Process (computer science)

Statuses of processes in modern OS.

Process is a program that is currently running. The ISO 9000: 2000 standard defines a process as a set of interconnected and interacting actions that transform incoming data into outgoing data.

A computer program in itself is just a passive sequence of instructions. While the process is the direct execution of these instructions.

Also, a process is called a running program and all its elements: address space , global variables , registers , stack , open files, and so on.

Content

Process Representation

Typically, a process in a computing system is represented (also said to “own”) the following resources:

  • image of executable machine code associated with the program ;
  • memory (usually some area of virtual memory ), which includes:
    • executable code;
    • input and output data of the process;
    • call stack (to track active routines );
    • a heap for storing intermediate results of calculations generated at runtime;
  • operating system resource descriptors allocated to the process, for example, a file
  • file descriptors (in Unix OS terminology) or “handles” (in Windows OS terminology);
  • security attributes, such as the owner and set of process permissions (valid operations);
  • processor state ( context ), such as:
    • register contents;
    • scheme for converting virtual addresses to physical ones;
    • etc.
The context of the current process is unloaded into memory when switching to another process is performed [1] .

The operating system stores most of the process information in the process table.

On operating systems that support threads (threads), threads also have their own resources. Usually this is only the state of the processor, although threads can use other resources.

To reduce the likelihood of processes influencing each other and the likelihood of system failure (for example, deadlocks or slipping ), the operating system provides isolation of processes and allocates the resources they need. The operating system also provides mechanisms for the interaction of processes in safe and predictable ways.

Representation of the process in memory

This section describes the process representation in memory of the Linux operating system and x86 architecture. This view differs little from many other multitasking operating systems and architectures. For example, in amd64 , the successor to x86, the call stack also grows from top to bottom, but the size of the address space is increased to 2 48 bytes. [2]

 
Representation of a program in memory in user space

Linux uses a flat memory model , and therefore, in this architecture, 2 32 bytes of memory are available to each process. All virtual memory is divided into user space and kernel space . The kernel space occupies one gigabyte of memory, starting with the oldest address. The rest of the space, that is, three gigabytes is reserved for user space.

The diagram on the right shows a representation of the user space of any process. The kernel space is the same for all processes, since only one kernel instance can exist in the operating system. After starting the program, processor instructions (machine code) and initialized data are imported into RAM. At the same time, startup arguments, as well as environment variables, are imported into the higher addresses.

The initialized data area stores read-only data. It can be, for example, string literals.

In the uninitialized data area, global variables are typically stored.

A heap is used to allocate memory while a program is running. On Linux, the mmap system call exists for this.

The stack area is used to call procedures .

An important detail is the presence of a random indent between the stack and the upper region, as well as between the initialized data region and the heap. This is done for security purposes, for example, to prevent other functions from being embedded on the stack.

Dynamic link libraries and file mappings are located between the stack and the heap.

Process Hierarchy

In multi-tasking operating systems, it became possible to work simultaneously with several processes. Operating systems with preemptive multitasking made it possible to feel the work of several processes simultaneously. At the same time, several process controls were required.

Unix

Unix is one of the first multitasking OS. Each process has a unique numeric identifier PID. The processes in it have a tree hierarchy, where the root is the init process with PID 1. The new process can be created with the fork system call, it will be an exact copy of the parent process. Any process other than init always has a parent process (PPID attribute ( English Parent PID )); processes whose parent has completed their work become child processes of init.

Processes are also grouped. The group calls setpgid and getpgid are responsible for managing the group identifier (PGID). PGID is equal to the PID of the group leader. The child process inherits the group from the parent. Groups are used to manage tasks .

Process groups are combined in sessions . The system call setsid is responsible for creating a new session. Processes from the same group cannot belong to different sessions. Therefore, the group leader cannot become the session leader: when creating a session, the child process automatically becomes the session leader and the leader of the new group. Sessions are used to track all processes that are started after a user logs in.

Each session can have no more than one control terminal . The terminal emulator has a command shell as a child (most often bash or sh), which, before starting, becomes the leader of a new session and sets the terminal as its manager.

Process Creation

The simplest operating system does not require the creation of new processes, since there is only one program running inside them that starts when the device is turned on. In more complex systems, new processes must be created. Usually they are created:

  • When the OS starts (for example, when device drivers initialize ),
  • When a request to create a process appears - occurs if a running process makes a system call .

Process States

The process, in addition to the main operating state, can be in other states, for example, expectations.

Linux

 
Conversion Graph

A process on Linux can be in one of the following states:

  • R (running / runnable) - the process is running or is waiting for its turn to run;
  • D - uninterrupted sleep - the process expects a specific event;
  • S - interrupted sleep - the process expects a specific event or signal;
  • T - stop - the process is suspended, for example, by the debugger;
  • Z ( zombie ) - the process has already completed, but has not yet passed its return code to the parent process.

Process Completion

At least 2 stages of completion:

  1. The process is removed from all planning queues , that is, the OS no longer plans to allocate any resources to the process,
  2. Collection of statistics on the resources consumed by the process, followed by its removal from memory .

Reasons for completing the process:

  • Normal output
  • Exit by exception or error,
  • Insufficient memory
  • Exceeding the time limit for the program,
  • Going beyond the allocated memory area ,
  • Invalid command (these programs are interpreted as instructions for the processor)
  • Security error (execution of an unprivileged command),
  • Completion of the parent process,
  • I / O error
  • Operator Intervention.

Notes

  1. ↑ E. Tannenbaum. Modern Operating Systems = Modern Operating Systems. - 2nd ed. - SPb. : Peter, 2002 .-- S. 59, 97 .-- 1040 s. - ISBN 5-318-00299-4 .
  2. ↑ AMD Corporation. Volume 2: System Programming (unopened) (PDF). AMD64 Architecture Programmer's Manual . AMD Corporation (December 2016). Date of appeal March 25, 2017.

Literature

  • E. Tanenbaum , A. Woodhall . “Operating Systems: Development and Implementation.” - SPb .: 2006. - ISBN 5-469-00148-2
  • E. Tanenbaum . “Modern operating systems. 2nd ed. ”- SPb .: Peter, 2005. - 1038 p.: Ill. ISBN 5-318-00299-4


Source - https://ru.wikipedia.org/w/index.php?title=Process_(informatics)&oldid=101451248


More articles:

  • Ruthenium Titan
  • Golden Globe Award (2016)
  • Zion Square (Tbilisi)
  • The Stadium Techno Experience
  • Newell's Old Boys
  • Rosario Central
  • Gimnasia and Esgrima (football club, La Plata)
  • Fortress
  • Qualification for the second division of the 2016 World Ice Hockey Championship (women)
  • Godred II (King of Maine)

All articles

Clever Geek | 2019