经典书籍翻译——深入理解Linux内核22

Processes
All operating systems use one fundamental abstraction: the process. A process can be defined either as “an instance of a program in execution” or as the “execution context” of a running program. In traditional operating systems, a process executes a single sequence of instructions in an address space; the address space is the set of memory addresses that the process is allowed to reference. Modern operating systems allow processes with multiple execution flows—that is, multiple sequences of instructions executed in the same address space.
进程
所有操作系统都使用了一个基本的抽象数据类型:进程。一个进程可以被定义为“正在执行程序的一个实例”或者正在运行的程序“执行上下文”。在传统的操作系统中,一个进程在地址空间中执行单独的指令序列,该地址空间是进程允许访问的内存地址集合;现代操作系统允许进程包含多个执行流——也就是说,多个指令序列会在相同的地址空间执行。

Multiuser systems must enforce an execution environment in which several processes can be active concurrently and contend for system resources, mainly the CPU.
Systems that allow concurrent active processes are said to be multiprogramming or multiprocessing. It is important to distinguish programs from processes; several processes can execute the same program concurrently, while the same process can execute several programs sequentially.

多用户系统必须强制构建多个进程可以同时活跃的运行环境,在这个环境中进程可以争夺系统资源——主要是CPU。系统并发活动进程的系统被称为多道程序或多任务;区分任务和进程非常重要,多个进程可以并发执行一个程序,而一个进程可以按顺序执行多个程序。

On uniprocessor systems, just one process can hold the CPU, and hence just one execution flow can progress at a time. In general, the number of CPUs is always restricted, and therefore only a few processes can progress at once. An operating system component called the scheduler chooses the process that can progress. Some operating systems allow only nonpreemptable processes, which means that the scheduler is invoked only when a process voluntarily relinquishes the CPU. But processes of a multiuser system must be preemptable; the operating system tracks how long each process holds the CPU and periodically activates the scheduler.Unix is a multiprocessing operating system with preemptable processes. Even when no user is logged in and no application is running, several system processes monitor the peripheral devices. In particular, several processes listen at the system terminals waiting for user logins. When a user inputs a login name, the listening process runs a program that validates the user password. If the user identity is acknowledged, the process creates another process that runs a shell into which commands are entered.
在一个单处理器系统中,在同一时刻只能有一个进程占据CPU,因此只能有一个执行流在进行。通常来说,CPU 的数量总是有限的,因此一次只能执行少量的进程。操作系统中由调度器来选择相应的进程来执行,有些操作系统只允许不可抢占式进程,这就意味着只有当前运行的进程主动放弃CPU资源的时候调度器才可以调用其他进程,但是多用户系统中的进程必须是可抢占的;操作系统记录每个进程占有CPU的时间然后周期性地启动调度器。Unix是一个可抢占式多进程操作系统,即使没有任何用户登录系统也没有程序在运行,仍然会有些系统进程在监视外设的状态。在特殊情况下,有几个进程会监听系统终端并等待用户登录。当一个用户输入登录名时,监听进程就会启动一个验证用户密码的程序,如果验证通过,那么这个进程就会创建另一个可以执行shell命令的新的进程。

When a graphical display is activated, one process runs the window manager, and each window on the display is usually run by a separate process. When a user creates a graphics shell, one process runs the graphics windows and a second process runs the shell into which the user can enter the commands. For each user command, the shell process creates another process that executes the corresponding program.
Unix-like operating systems adopt a process/kernel model. Each process has the illusion that it’s the only process on the machine, and it has exclusive access to the operating system services. Whenever a process makes a system call (i.e., a request to the kernel, see Chapter 10), the hardware changes the privilege mode from User Mode to Kernel Mode, and the process starts the execution of a kernel procedure with a strictly limited purpose. In this way, the operating system acts within the execution context of the process in order to satisfy its request. Whenever the request is fully satisfied, the kernel procedure forces the hardware to return to User Mode and the process continues its execution from the instruction following the system call.
当图形界面被激活时,一个进程运行窗口管理器,每个显示的窗口通常由一个单独的进程驱动。当一个用户创建一个可视化shell时,一个进程运行可视化窗口,另一个进程运行相应的shell,用户可以在里面输入命令。对每个用户命令来说,shell进程会创建相应的进程来执行相应的程序。
类UNIX操作系统采用进程/内核模型,每个进程都会让人产生错觉,认为该进程时机器中唯一的进程,并且对操作系统提供的服务具有独占访问权限。无论进程什么时候执行系统调用,硬件都会从用户模式切换到内核模式,同时进程会执行一个内核程序,其目的受到严格的限制。通过这种方式,操作系统在进程的执行上下文中操作相应的资源,从而满足进程的请求;只要进程的请求完全满足,内核程序就会强制硬件返回用户模式,进程就会从系统调用后面的指令继续执行。

猜你喜欢

转载自blog.csdn.net/m0_37546257/article/details/121442698