操作系统 面试问题

Here you will get list of 60+ commonly asked operating system interview questions and answers. These os questions are helpful for freshers as well as experienced.

在这里,您将获得60多个常见的操作系统面试问题和答案的列表。 这些操作系统问题对于新生和有经验的人都是有帮助的。

1. What is operating system?

1.什么是操作系统?

Operating system can be defined as an interface between user’s program and hardware.

操作系统可以定义为用户程序和硬件之间的接口。

2. What is main purpose of operating system?

2.操作系统的主要目的是什么?

The main purpose of OS is to manage hardware and software resources and provides common services for our programs. It provides a suitable platform to execute our program (jobs).

操作系统的主要目的是管理硬件和软件资源,并为我们的程序提供通用服务。 它提供了一个合适的平台来执行我们的程序(工作)。

3. What are different types of operating system?

3.什么是不同类型的操作系统?

There are generally two types of operating system which are as follows:

通常有两种类型的操作系统,如下所示:

  1. Batch Operating System.批处理操作系统。
  2. Multiprogramming Operating System多程序操作系统

Now this Multiprogramming Operating System can be broadly classified as:

现在,该多程序操作系统可以大致分为:

  • Multitasking Operating System多任务操作系统
  • Multiprocessing Operating System多处理操作系统
  • Real Time Operating System实时操作系统

4. What are different components of operating system?

4.操作系统有哪些不同组件?

The main components of operating system are:

操作系统的主要组件是:

  1. Kernel核心
  2. Process Management流程管理
  3. File System文件系统
  4. Memory Management内存管理
  5. I/O ManagementI / O管理

Thus operating system is not an individual component but it has may sub components as stated above which makes our job easier.

因此,操作系统不是一个单独的组件,而是具有上述子组件的子组件,这使我们的工作更加轻松。

5. What are the goals of OS?

5.操作系统的目标是什么?

Basically there are two goals of Operating System, those are:

操作系统基本上有两个目标,分别是:

  1. Primary : Convenience小学:便利
  2. Secondary : Efficiency次要:效率

6. Explain the different types of Operating System?

6.解释不同类型的操作系统?

  • Batch Operating System:批处理操作系统:

In this type of Operating System all the jobs are submitted to computer at once and are executed in the order of submission without any preemption (means no job can be taken out until they complete).

在这种类型的操作系统中,所有作业都立即提交到计算机,并按提交顺序执行而没有任何先占权(意味着在完成之前无法取出任何作业)。

  • Multiprogramming Operating System多程序操作系统

It’s an extension of Batch OS where several jobs would be in the main memory at once and would be executed in some order for some specified amount of time.

它是批处理OS的扩展,其中几个作业将一次存储在主内存中,并以一定的顺序执行一定的时间。

Now we will look into its sub types:

现在,我们将研究其子类型:

  • Multi-tasking Operating System:多任务操作系统:

In this type of Operating System more than one task are executed simultaneously on a single processor machine. In fact there is a switching of CPU among the processes (jobs) at a very sharp pace that it seems to done parallel to the end user.

在这种类型的操作系统中,一个处理器上同时执行多个任务。 实际上,进程(作业)之间的CPU切换速度非常快,这似乎与最终用户并行。

  • Multiprocessing Operating System:多处理操作系统:

It is the ability of an operating system to execute more than one process simultaneously on a multi-processor machine. In this, a computer uses more than one CPU at a time.

这是操作系统在多处理器计算机上同时执行多个进程的能力。 在这种情况下,一台计算机一次使用多个CPU。

  • Real Time Operating System:实时操作系统:

In such operating System there is a specified time allotted for each job. It’s useful in critical application like military, satellite etc.

在这样的操作系统中,为每个作业分配了指定的时间。 在军事,卫星等关键应用中很有用。

7. What is kernel?

7.什么是内核?

Kernel is the core part of the Operating System responsible for managing the communication between the software (user level applications) and the hardware (CPU, disk memory etc.). The main tasks of the kernel are:

内核是操作系统的核心部分,负责管理软件(用户级应用程序)和硬件(CPU,磁盘内存等)之间的通信。 内核的主要任务是:

  • Process management流程管理
  • Device management设备管理
  • Memory management内存管理
  • Interrupt handling中断处理
  • I/O communicationI / O通讯
  • File system etc.文件系统等

8. What are different types of kernel?

8.什么是不同类型的内核?

We have three important types of kernel named:

我们有三种重要的内核类型:

  • Monolithic Kernel:整体内核:

It can be seen as a whole kernel that is full-fledged kernel, with all the services running.

可以将其视为一个完整的内核,它是成熟的内核,所有服务都在运行。

Example: UNIX

示例:UNIX

  • Micro Kernel:微内核:

It is kernel with a limited services that is with some important services running.

它是具有有限服务的内核,并且正在运行一些重要服务。

Example: QNX-real time OS

示例:QNX实时操作系统

  • Hybrid Kernel:混合内核:

It combines the aspect of both monolithic as well as micro kernel.

它结合了单片以及微内核的方面。

Example: Microsoft NT kernel

示例:Microsoft NT内核

9. What is user space and kernel space?

9.什么是用户空间和内核空间?

These are two important region of a memory.

这是内存的两个重要区域。

User space: It is a region of memory where normal user processes run (i.e. everything other than Kernel).

用户空间:这是运行普通用户进程(即除内核以外的所有进程)的内存区域。

Kernel space: It is a region of memory where code of kernel resides and executes. It is considered to be privileged part of a memory invoked by system calls. It is also known as System space.

内核空间:这是内核代码驻留和执行的内存区域。 它被认为是系统调用所调用的内存的特权部分。 也称为系统空间。

10. What is process?

10.什么是过程?

A running program is called as a process or it’s an active instance of program that is under execution.

一个正在运行的程序称为进程,或者它是正在执行的程序的活动实例。

A process is an entity created by Operating system to execute the program.

进程是操作系统创建的用于执行程序的实体。

In Linux, we can use “ps” command to see running process.

在Linux中,我们可以使用“ ps”命令查看运行过程。

Example: Any .exe in windows OS is a process like skype.exe etc

例如:Windows OS中的任何.exe都是像skype.exe等的进程

11. What are different type of process?

11.什么是不同类型的过程?

There are two types of process that is i) user space process and ii) Kernel space process.

有两种类型的过程,即i)用户空间过程和ii)内核空间过程。

12. What is difference between a program and a process?

12.程序和流程之间有什么区别?

A program is a set of instructions that are to perform a designated task, whereas the process is an operation which accepts the given instructions and perform the task as per the code, called ‘execution of instructions’.

程序是一组执行指定任务的指令,而过程是一种接受给定指令并按照称为“指令执行”的代码执行任务的操作。

Thus a program is a passive entity residing at secondary memory and a process is an active entity residing in the main memory.

因此,程序是驻留在辅助存储器中的被动实体,而进程是驻留在主存储器中的主动实体。

13. Explain the different states of a process?

13.解释流程的不同状态?

A process can go through following states in its lifecycle:

流程可以在其生命周期中经历以下状态:

  • New:新:

This is the first state when a process is created or just started. It resides in secondary memory.

这是创建或刚启动流程时的第一种状态。 它位于辅助内存中。

  • Ready:准备:

This state signifies that the process is ready to be assigned to the processor that is ready to execute.

此状态表示已准备好将进程分配给准备执行的处理器。

  • Running:运行:

This state signifies that process has been given to the processor and its instruction are getting executed.

此状态表示已将处理交给处理器,并且其指令正在执行。

  • Waiting:等候:

This state signifies that a process is waiting for some kind of resource or an event be it a user input or waiting for any file to become available.

此状态表示进程正在等待某种资源或事件,无论是用户输入还是正在等待任何文件可用。

  • Terminated:终止:

The process can be terminated normally or abnormally.

该过程可以正常或异常终止。

Normal termination means that process has done with its complete execution whereas abnormal means that process has been terminated without completing its task.

正常终止表示进程已完成其完整的执行,而异常意味着进程已终止但未完成其任务。

Note: Any process has to go minimum four states (new->ready->running->terminated).

注意:任何进程都必须至少进入四个状态(新->就绪->运行->已终止)。

14. Which is the first process to be created by OS?

14. OS首先创建哪个进程?

Init process is the first process to be created by OS. It provides the environment for the other process to be created later.

初始化过程是OS创建的第一个过程。 它为以后创建其他进程提供了环境。

15. How are process identified?

15.如何识别过程?

Any process can be identified by a term called its id that is process id (pid).

任何进程都可以通过称为其ID的术语来标识,该术语是进程ID(pid)。

16. What is fork ()?

16.什么是fork()?

Fork is a system call which is responsible for creating a copy of a current process. The current process is termed as parent process and the created process is termed as child process.

Fork是一个系统调用,负责创建当前进程的副本。 当前进程称为父进程,创建的进程称为子进程。

On success it returns pid of the child process to parents process and Zero is returned to child process.

成功后,它将子进程的pid返回父进程,将零返回到子进程。

17. What is system call?

17.什么是系统调用?

It’s like a way by which any user level program ask for the services offered by a kernel.

这就像任何用户级程序要求内核提供的服务的方式。

It acts as an interface between a process and the operating system.

它充当进程和操作系统之间的接口。

18. What is program counter?

18.什么是程序计数器?

It a pointer which points to the next instruction to be executed by a compiler.

它是指向编译器要执行的下一条指令的指针。

19. What are the different attributes of a process?

19.流程的不同属性是什么?

Some of the important attributes of a process are:

流程的一些重要属性是:

  • Process id (pid)进程ID(PID)
  • Parent process id (PPid)父流程编号(PPid)
  • Process stateCraft.io状态
  • Scheduling parameter调度参数
  • Program counter and different registers.程序计数器和不同的寄存器。

This is also referred as context of a process.

这也称为过程的上下文。

20. What is Process control Block (PCB)?

20.什么是过程控制块(PCB)?

It is like a data structure which hold all information (attributes) of a process.

就像一个数据结构,它保存进程的所有信息(属性)。

21. What are different section of a process?

21.流程的不同部分是什么?

There is four important section of a process as stated below:

流程中有四个重要部分,如下所述:

  • Stack: contains local variables ,returns address堆栈:包含局部变量,返回地址
  • Heap: Dynamically allocated memory via malloc, calloc,realloc堆:通过malloc,calloc,realloc动态分配的内存
  • Data: contains global and the static variables数据:包含全局变量和静态变量
  • Code or text: contains code, program counter and content of processor’s register.代码或文本:包含代码,程序计数器和处理器寄存器的内容。

Note:

注意:

  • Stack and the Heap section are extendible that is stack can grow down and heap can grow up.Stack和Heap部分是可扩展的,即堆栈可以向下扩展,而堆栈可以向上扩展。
  • It is in the same order as mentioned above.它与上述顺序相同。

22. What is context switching?

22.什么是上下文切换?

It is switching of a processor from one process/thread to another. It is also called Task switch or process switch.

它是将处理器从一个进程/线程切换到另一个进程/线程。 也称为任务开关或过程开关

23. What is inode?

23.什么是inode?

Inode is a data structure which holds all the attributes of a file. It is also called index number.

索引节点是一种数据结构,其中包含文件的所有属性。 也称为索引号。

Some of the attributes of file are:

文件的一些属性是:

  • File type文件类型
  • Permission允许
  • File size文件大小
  • Time when last it is modified最后修改的时间

Note: Please while  reading thread concept, try to relate all this with process, thread will have its own, all those attributes as that of a process like its id(tid), scheduling parameter/policy etc. and  concept like context switching, different section etc. Thus try to relate all thread’s concept with that of a process.

注意:请在阅读线程概念时,尝试将所有这些与进程相关联,线程将拥有自己的属性,所有这些属性都是进程的属性,例如其id(tid),调度参数/策略等,以及上下文切换等概念,不同因此,请尝试将所有线程的概念与进程的概念相关联。

24. What is thread?

24.什么是线程?

Thread is a concurrent unit of execution within a process. A process can have multiple threads where each thread can perform a different task independently, thus increasing the efficiency of a process. A process always has one thread by default called main thread which is executed first.

线程是进程内的并发执行单元。 一个进程可以具有多个线程,其中每个线程可以独立执行不同的任务,从而提高了进程的效率。 默认情况下,一个进程始终有一个线程称为主线程,该线程首先执行。

Example:

例:

  • Word processor, a background thread may check spelling and grammar while a foreground thread processes user input (keystrokes).字处理器中,后台线程可以检查拼写和语法,而前台线程则可以处理用户输入(按键)。
  • Web server – Multiple threads allow for multiple requests to be served simultaneously, without having to service requests sequentially.Web服务器–多个线程允许同时处理多个请求,而不必依次处理请求。

25. State the benefits of a thread?

25.陈述线程的好处?

Some of the common advantages associated with threads are:

与线程相关的一些常见优点是:

  • Responsiveness:响应能力:

A process with thread are said to be more responsiveness than a process without thread because even if one thread is blocked or waiting for some resources the other thread still continue to function.

具有线程的进程比没有线程的进程具有更高的响应能力,因为即使一个线程被阻塞或等待某些资源,另一个线程仍然可以继续运行。

  • Lighter:打火机:

A thread is considered to be lighter than a process in terms of resource sharing and run time overhead. Most of the resource of a process are shared by all its thread making it lighter.

就资源共享和运行时开销而言,线程被认为比进程轻。 进程的大多数资源都由其所有线程共享,从而使其更轻便。

  • Throughput:吞吐量:

It improves the throughput of a multithreaded application, multiprocessor environment.

它提高了多线程应用程序,多处理器环境的吞吐量。

  • Economy:经济:

Creating and managing thread is much faster (context switching is faster) than performing same task for processes.

创建和管理线程比为进程执行相同任务要快得多(上下文切换更快)。

26. State the disadvantages associated with thread?

26.陈述与线程相关的缺点吗?

  • Robustness:坚固性:

It’s not as robust as process since if any one thread is terminated abnormally, it leads to entire process termination.

它不像进程那样健壮,因为如果任何一个线程异常终止,它将导致整个进程终止。

Thus many RTOS (Real Time Operating System) application uses processed over threads.

因此,许多RTOS(实时操作系统)应用程序使用线程处理。

  • Increased Complexity复杂性增加

It is more complex than a process in terms of synchronization overhead.

就同​​步开销而言,它比过程更复杂。

27. What is difference between a process and a threads?

27.进程和线程之间有什么区别?

Process Thread
Process is used for heavyweight task Threads are used for small task(lightweight)
Processes are less responsive than threads Threads are more responsive than process
Processes are more robust than threads Threads are less robust
Each process will have its own address space. Threads are within a process thus share same address space(memory)
Processes have less synchronization overhead since all have separate address space(memory) Since they share same address space, synchronization is more overhead than process
处理 线
过程用于重量级任务 线程用于小型任务(轻量级)
进程的响应速度不如线程 线程比进程更敏感
进程比线程更健壮 线程不那么健壮
每个进程将有其自己的地址空间。 线程在进程内,因此共享相同的地址空间(内存)
进程具有较少的同步开销,因为所有进程都有单独的地址空间(内存) 由于它们共享相同的地址空间,因此同步比处理更多的开销

28. What are different types of threads?

28.什么是不同类型的线程?

There are two types of threads:

有两种类型的线程:

  • User level thread : java thread用户级线程:java线程
  • Kernel level thread: POSIX thread.内核级线程:POSIX线程。

29. What is scheduler?

29.什么是调度程序?

It is one of the component of kernel responsible for scheduling that is deciding when to run which process.

它是负责调度的内核组件之一,它决定何时运行哪个进程。

30. What are different types of scheduler?

30.有哪些不同类型的调度程序?

There are three types of scheduler:

调度程序分为三种:

  • Long Term scheduler:长期调度程序:

It is also called job scheduler responsible for selecting processes from queue (job pool/secondary memory) and loading them to main memory for execution.

它也称为作业调度程序,负责从队列(作业池/辅助内存)中选择进程并将其加载到主内存中以执行。

  • Short term scheduler:短期调度程序:

It is also called CPU scheduler responsible for selecting a process among processes that are ready to execute and allocate CPU to one of them.

它也称为CPU调度程序,负责在准备执行的进程中选择一个进程并将CPU分配给其中一个。

This is nothing but a change of state of process from ready to running state. It is also called dispatcher.

这不过是将流程状态从就绪状态更改为运行状态而已。 也称为调度程序。

  • Medium term scheduler:中期调度程序:

It is also called swapper responsible for swapping a process from main memory to secondary memory in case if some high priority process needs to be given chance for execution.

它也称为交换程序,负责将某个进程从主内存交换到辅助内存,以防某些高优先级的进程需要执行的机会。

It reduces the degree of multiprogramming (many processes in main memory).

它降低了多重编程的程度(主存储器中的许多进程)。

31. What is preemptive and non-preemptive scheduling algorithm?

31.什么是抢占式和非抢占式调度算法?

A scheduling algorithm is preemptive if, once a process has been given the CPU can take away. The strategy of allowing processes that are logically runnable to be temporarily suspended is called Preemptive Scheduling and allowing the process to run till completion is called non-preemptive scheduling.

如果一旦指定了进程,CPU便会抢走,则调度算法是抢先的。 允许将逻辑上可运行的进程暂时挂起的策略称为“抢先式调度”,将允许进程运行直到完成的策略称为“非抢先式调度”。

32. What are different types of scheduling algorithm?

32.有哪些不同类型的调度算法?

There are four different types of scheduler:

有四种不同类型的调度程序:

  • First come First serve(FCFS): First came process is served first先到先得(FCFS):先到先得流程
  • Round Robin(RR):Each process is given a quantum amount of timeRound Robin(RR):每个过程都被分配了一个量子时间
  • Shortest job first(SJF):Process with lowest execution time is given first preference最短作业优先(SJF):优先选择执行时间最短的进程
  • Priority scheduling (ps): Priority value called (nice value) is used for selecting process. Its value is from 0 to 99. 0 being max and 99 being least.优先级调度(ps):优先级值(nice value)用于选择进程。 其值是从0到99。0是最大值,而99是最小值。

33. What are different performance metric for scheduler?

33.调度程序有哪些不同的性能指标?

There are five performance metric for scheduler, those are as follows:

调度程序有五个性能指标,如下所示:

  • CPU Utilization:CPU使用率:

Percentage of time that the CPU is doing useful work (I.e. not being idle). 100% is perfect.

CPU正在执行有用工作(即不处于空闲状态)的时间百分比。 100%完美。

  • Wait time:等待时间:

Average time a process spends for its turn to get executed.

流程执行该流程所花费的平均时间。

  • Throughput:吞吐量:

Number of processes completed / time unit.

完成的进程数/时间单位。

  • Response Time:响应时间:

Average time elapsed from when process is submitted until useful output is obtained.

从提交流程到获得有用的输出所经过的平均时间。

  • Turnaround Time:周转时间:

Average time elapsed from when process is submitted to when it has completed.

从流程提交到完成的平均时间。

34. What is daemon process?

34.什么是守护进程?

A daemon process is one which runs at the background unlike the other foreground processes without the intervention of the user. It ends with “d”.

守护进程是在后台运行的守护进程,与其他前台进程不同,它无需用户干预。 它以“ d”结尾。

Example: crond is a daemon process in Linux operating system which is responsible for scheduling of an event like sending packets statistics at every 1 hours to server can be done with the help of crond daemon process.

示例:crond是Linux操作系统中的守护进程,它可以安排事件的调度,例如可以在crond守护进程的帮助下完成每1小时向服务器发送一次数据包统计信息。

35. What are different types of process in Linux?

35. Linux中有哪些不同类型的进程?

There are three different types of process in Linux, those are:

Linux中有三种不同类型的过程,分别是:

  • Interactive-Foreground互动前景
  • Batch批量
  • Daemon-Background守护程序背景

36. What is deadlock?

36.什么是死锁?

A deadlock is a situation where two or more process or threads sharing the same resource are effectively preventing each other from accessing the resource. In simple terms the resource needed by one process/threads are being used by others and so on, thus none of the process can continue executing leading to deadlock.

死锁是指两个或多个共享同一资源的进程或线程有效地阻止了彼此访问资源的情况。 简单来说,一个进程/线程所需的资源正在被其他进程/线程使用,依此类推,因此任何进程都无法继续执行,从而导致死锁。

37. What are the conditions required for deadlock to happen?

37.发生僵局需要什么条件?

There are four conditions required for deadlock which are stated below

死锁需要满足以下四个条件

Mutual Exclusion: At least one resource is held in a non-sharable mode that is only one process at a time can use the resource. If another process requests that resource, the requesting process has to wait till it is released.

互斥:至少一种资源以不可共享的方式持有,一次只能有一个进程使用该资源。 如果另一个进程请求该资源,则请求进程必须等待直到释放它。

Hold and Wait: There must exist a process that is holding at least one resource and is waiting to acquire additional resources that are currently being held by other processes.

保持并等待:必须存在一个进程,该进程至少持有一个资源,并且正在等待获取其他进程当前正在持有的其他资源。

No Preemption: Resources cannot be preempted; that is, a resource can only be released after the process has completed its task.

无抢占:资源不能抢占; 也就是说,只能在进程完成其任务后才释放资源。

Circular Wait: There must exist a set {p0, p1,…..pn} of waiting processes such that p0 is waiting for a resource which is held by p1, p1 is waiting for a resource which is held by p2,…, pn-1 is waiting for a resource which is held by pn and pn is waiting for a resource which is held by p0.

循环等待:必须存在一组{p0,p1,..... pn}等待进程,以便p0正在等待由p1保留的资源,p1正在等待p2,...,pn保留的资源-1正在等待pn保留的资源,而pn正在等待p0保留的资源。

Note: All the four conditions mentioned above has to be satisfied for deadlock to happen.

注意:必须满足上述所有四个条件才能发生死锁。

38. What is race condition?

38.什么是比赛条件?

Race condition is an undesirable situation where two or more threads/process are trying to access and change the value of data shared by them and the outcome of the operation depends upon the order in which the execution happens.

竞争条件是一种不希望的情况,其中两个或多个线程/进程试图访问并更改它们共享的数据的值,并且操作的结果取决于执行的顺序。

Thus it lead to data inconsistency and loss of its value as both threads are racing to change/access the shared data.

因此,当两个线程都在争相更改/访问共享数据时,它会导致数据不一致并失去其价值。

Example:

例:

Assume x =5;

假设x = 5;

Thread 1

线程1

x =x+1;

x = x + 1;

write x;

写x;

Thread 2

线程2

x=x+10;

x = x + 10;

write x;

写x;

Assume just before first write the first thread is suspended and control comes to second thread thus it increments the value of x by 10 and writes the value that is now x becomes 15.

假设在第一次写入之前,第一个线程被挂起,控制权进入第二个线程,因此它将x的值增加10,然后写入现在x的值变为15。

In this case we can see that value of x depends upon the order in which the thread executes and the first value of x is lost that x=x+1=5+1=6. Thus there is clear inconsistency among the value of x because of race condition. Here x is the shared variable among both the threads upon which both are racing to access/update its value. To avoid such inconsistencies we need a proper synchronization mechanism like semaphore, mutex (discussed later)

在这种情况下,我们可以看到x的值取决于线程执行的顺序,并且x的第一个值丢失,即x = x + 1 = 5 + 1 = 6。 因此,由于竞争条件,x值之间存在明显的不一致。 在这里,x是两个线程都在争夺访问/更新其值的线程之间的共享变量。 为了避免这种不一致,我们需要一个适当的同步机制,例如信号量,互斥量(稍后讨论)。

39. What is Zombie process?

39.什么是僵尸进程?

A zombie process also called defunct process is one which has completed its execution and is in terminated state but still has entry in the process table. It is denoted by “Z”. It shows that still the resources held by process are not freed upon termination.

僵尸进程(也称为已终止进程)是已完成执行并处于终止状态但仍在进程表中具有条目的进程。 用“ Z”表示。 它表明,进程保留的资源仍然不会在终止时释放。

It is dangerous because at one point of time system may run out of memory.

这很危险,因为在某个时间点系统可能会用完内存。

40. What is synchronization?

40.什么是同步?

As the name suggest it means a proper co-ordination among processes while running in terms of resources. It means sharing system resources by a process in such a way that concurrent access to shared data is handled thereby minimising the chance of inconsistent data as we saw in Race condition.

顾名思义,它意味着在运行资源时在流程之间进行适当的协调。 这意味着通过一种过程来共享系统资源,这样就可以处理对共享数据的并发访问,从而最大程度地减少了在竞赛情况下看到不一致数据的机会。

41. What are different synchronization mechanism?

41.同步机制有哪些不同?

Some of the common synchronization mechanism are:

一些常见的同步机制是:

  • Semaphore信号
  • Mutex互斥体

42. What is semaphore?

42.什么是信号量?

Semaphore is one of the simplest synchronization mechanism used to control access to a common resource by multiple processes in a concurrent system such as a multiprogramming operating system.

信号量是最简单的同步机制之一,用于控制并发系统(例如,多程序操作系统)中的多个进程对公共资源的访问。

It’s a variable with a value range between 0 to N where N = maximum resources -1;

它是一个变量值,范围在0到N之间,其中N =最大资源-1;

43. What are different types of semaphore?

43.有哪些不同类型的信号量?

There are two types of semaphore, those are:

信号量有两种,分别是:

  • Binary Semaphore:二进制信号量:

Semaphore which can have only two values either 0 or 1. It is also called Boolean semaphore controlling/protecting just one resource.

信号量只能有两个值0或1。它也称为布尔信号量,仅控制/保护一个资源。

  • Counting Semaphore:计数信号量:

Semaphore whose value can be in the range of 0 to n where n =max -1; where max is nothing but the maximum resource.

信号量,其值可以在0到n的范围内,其中n = max -1; 其中max就是最大资源。

When number of resources a semaphore protects is greater than 1, it’s called counting semaphore.

当信号灯保护的资源数量大于1时,称为计数信号灯。

44. How is synchronization achieved by semaphore or What are different operations performed on semaphore variables?

44.通过信号量如何实现同步?或者对信号量变量执行哪些不同的操作?

There are two operations which are performed on semaphore which helps in synchronization, those are:

有两种对信号量执行的有助于同步的操作,它们是:

  • Wait:等待:

If the semaphore value is not negative, decrement the value by 1.

如果信号量值不为负,则将该值减1。

  • Signal:信号:

Increments the value of semaphore by 1.

将信号量的值增加1。

For example:

例如:

Say the value of semaphore variable is initialized by 1 and if one process tries to use the shared variable, it decrements the value by 1 and access it. In the meantime if other process attempts to access it, it finds the semaphore variable 0 thus has to wait till the first process completes its task and increments the value back to 1.

假设信号量变量的值由1初始化,并且如果一个进程尝试使用共享变量,则它将值减1并访问它。 同时,如果其他进程尝试访问它,它会发现信号量变量0,因此必须等到第一个进程完成其任务并将其值增加回1。

Thus form the above explanation we can see that there is a proper synchronization (controlling one process form another) avoiding any race condition.

因此,从上面的解释中我们可以看到,存在适当的同步(从另一个进程控制一个进程),避免了任何竞争状况。

45. What is mutex?

45.什么是互斥锁?

Mutex is a locking mechanism which allows only one process to access the resource at a time.

Mutex是一种锁定机制,一次仅允许一个进程访问资源。

It stands for mutual exclusion and ensure that only one process can enter the critical section at a time.

它代表互斥,并确保一次只能有一个过程进入关键部分。

46. What is critical section of code?

46.代码的关键部分是什么?

As the name suggest it is that section or part of code which has variables or other resources which is being shared by two process, and if allowed to access may lead to race condition. To avoid this we need a mutex which ensures only one process can enter the critical section of code at a time.

顾名思义,这是代码的一部分或一部分具有由两个进程共享的变量或其他资源,如果允许访问,则可能导致竞争状态。 为了避免这种情况,我们需要一个互斥体,以确保一次只能有一个进程输入关键的代码部分。

47. Differentiate between semaphore and mutex?

47.区分信号量和互斥量?

Below stated are some important difference held between mutex and semaphore

以下是互斥量与信号量之间的一些重要区别

                         Semaphore                               Mutex
It is a synchronization mechanism It is a locking mechanism
A Semaphore controls access to a shared pool of resources. It provides operations to Wait () until one of the resources in the pool becomes available, and Signal () when it is given back to the pool. A Mutex controls access to a single shared resource.
The other process can also the release the lock held by others The process which has acquired the lock can only release the lock
信号 互斥体
这是一个同步机制 这是一种锁定机制
信号量控制对共享资源池的访问。 它提供以下操作:Wait()直到池中的一种资源可用,然后提供Signal()到池中的一种资源。 Mutex控制对单个共享资源的访问。
其他过程也可以释放他人持有的锁 已获取锁的进程只能释放锁

48. What do you mean by virtual memory?

48.虚拟内存是什么意思?

Virtual memory is a memory management scheme used by operating system which allows a system to compensate for the shortage of physical memory.

虚拟内存是操作系统使用的内存管理方案,它允许系统补偿物理内存的不足。

Virtual address space is increased using active memory in RAM and inactive memory in hard disk drives (HDDs) to form contiguous addresses that hold both the application and its data.

通过使用RAM中的活动内存和硬盘驱动器(HDD)中的不活动内存来增加虚拟地址空间,以形成包含应用程序及其数据的连续地址。

49. What do you mean by logical and physical address?

49.逻辑和物理地址是什么意思?

Logical Address:

逻辑地址:

It can be defined as an address generated by CPU, later these addresses are mapped to physical address with the help of mechanism called paging (discussed later).

可以将其定义为CPU生成的地址,稍后这些地址将在称为分页的机制的帮助下映射到物理地址(稍后讨论)。

Physical Address:

实际地址:

It is nothing but the actual address that belongs to main memory where our program resides for execution.

它不过是属于程序要执行的主内存的实际地址。

50. What is paging?

50.什么是分页?

The mapping from virtual to physical address is done by the memory management unit (MMU) which is a hardware device and this mapping is known as paging technique.

从虚拟地址到物理地址的映射是由作为硬件设备的内存管理单元(MMU)完成的,这种映射称为分页技术。

It ensures that the physical address of space to be non-contiguous. In this the virtual memory is divided into fixed size pages and the physical memory is divided into equal size called page frames.

它确保空间的物理地址不连续。 在这种情况下,虚拟内存被分为固定大小的页面,而物理内存被分为相等大小的称为页面帧的页面。

51. What is the size of each page?

51.每页大小是多少?

The size of page is 4k.

页面大小为4k。

52. What is demand paging?

52.什么是需求分页?

It is quite similar to a paging system with swapping where pages are loaded into main memory only on demand ,till then the processes resides in secondary memory.

它与分页系统非常相似,后者具有交换功能,即仅按需将页面加载到主内存中,直到进程驻留在辅助内存中。

For any process to execute, its pages are loaded into main memory, thus the entire page is not brought into main memory rather the pages are loaded only on demand not in advance. This is referred as demand paging.

对于要执行的任何进程,其页面均被加载到主存储器中,因此不会将整个页面带入主存储器中,而是仅根据需求而不是事先加载页面。 这称为需求分页。

Example:

例:

We have a process responsible for database function like insert, query, delete and thus it should be understood that this process is divided into pages say one page for each function and at certain point of time, it needs to perform query so there is no point in loading the entire process (pages) rather just the page related to query function.

我们有一个过程负责数据库功能,例如插入,查询,删除,因此应该理解,该过程分为多个页面,每个功能说一页,并且在某个时间点需要执行查询,因此没有意义加载整个过程(页面),而不仅仅是加载与查询功能相关的页面。

53. What is page fault?

53.什么是页面错误?

As the name suggest, we are looking for certain page in main memory and it is not found, its termed as page fault else page hit.

顾名思义,我们正在主内存中查找某些页面,但找不到该页面,称为页面错误或其他页面命中。

54. What is page replacement algorithm and name it?

54.什么是页面替换算法并命名?

As above we have seen that there might be situation of page fault, in that case we need to bring that page from secondary memory to main memory but if there is no room for new page in the main memory, some page from the main memory has to be replaced with new page form secondary memory. This is called page replacement and one of the common algorithms is Least Recently Used (LRU) that is replace the page that has been unused for longest time.

如上所述,我们已经看到可能存在页面错误的情况,在这种情况下,我们需要将该页面从辅助存储器带到主存储器,但是如果主存储器中没有空间容纳新页面,则主存储器中的某些页面会用新的页面形式的辅助存储器替换。 这被称为页面替换,并且最常用的算法之一是最近最少使用(LRU),它是用来替换最长时间未使用的页面。

55. What is cache?

55.什么是缓存?

Cache memory is a high speed memory in the CPU that is used for faster access to data. It provides the processor with the most frequently requested data

高速缓冲存储器是CPU中的高速存储器,用于更快地访问数据。 它为处理器提供最常请求的数据

56. What is TLB?

56.什么是TLB?

It is a hardware cache responsible for speeding up the translation of logical address to physical address that is mapping between logical and physical address.

它是一个硬件高速缓存,负责加速逻辑地址到物理地址(即逻辑地址和物理地址之间的映射)的转换。

It contains the page table entries which is most recently used, thus before looking into main memory for page, TLB is searched if not found main memory lookup is done for required page.

它包含最近使用的页表条目,因此在查找主内存页之前,如果未找到所需页的主内存查找,则搜索TLB。

57. What is fragmentation and state its types?

57.什么是碎片并说明其类型?

As we saw above that there is frequent swapping of page in and out form memory, the free space in main memory is broken into small pieces. It happens after sometime the processes cannot be allocated to memory blocks considering their small size and memory blocks remains unused. This problem is called fragmentation.

正如我们在上面看到的,页面内存的换入和换出很频繁,主内存中的可用空间被分成小块。 考虑到它们的体积小且内存块仍未使用,有时会在无法将进程分配给内存块后发生。 此问题称为碎片。

There are two types of fragmentation:

碎片有两种类型:

  • Internal fragmentation:内部碎片:

Memory block assigned to process is bigger. Some portion of memory is left unused, as it cannot be used by another process.

分配给进程的内存块更大。 内存的某些部分未被使用,因为它不能被另一个进程使用。

  • External fragmentation:外部碎片:

Total memory space is enough to satisfy a request or to reside a process in it, but they are  not contiguous, so it cannot be used.

总内存空间足以满足请求或在其中驻留进程,但是它们不是连续的,因此无法使用。

58. What is IPC and state some of them?

58.什么是IPC,并说明其中一些?

IPC means inter process communication- process to process notification, process to process synchronization which allows a programmer to coordinate activities among different program processes that can run concurrently in an operating system

IPC表示进程间通信-进程到进程的通知,进程到进程的同步,这使程序员可以协调可以在操作系统中同时运行的不同程序进程之间的活动

Some of the common IPC mechanism are:

一些常见的IPC机制是:

  • Message Queue:消息队列:

A queue of messages that is maintained between processes used for exchange for messages and other important information among processes.

在进程之间维护的消息队列,用于在进程之间交换消息和其他重要信息。

  • Shared Memory:共享内存:

In this memory (page) is shared among the processes in user space and one process can write into it and other can read.

在该内存(页面)中,用户空间中的进程之间共享该内存(页面),一个进程可以写入其中,而另一个可以读取。

  • Pipe:管:

A pipe is a technique for passing information from one program process to another. Basically, a pipe passes a parameter such as the output of one process to another process which accepts it as input.

管道是一种用于将信息从一个程序进程传递到另一个程序进程的技术。 基本上,管道将一个过程的输出之类的参数传递给另一个接受该过程作为输入的过程。

Example:

例:

ps –ef | grep “skype”

ps –ef | grep“ skype”

What it does that the output of “ps –ef” is given as an input to “grep” command with the help of pipe and “ps” is used in Linux to get the running process on system and “grep” is used for search.

在管道的帮助下,将“ ps –ef”的输出作为“ grep”命令的输入,在Linux中使用“ ps”获取系统上正在运行的进程,而使用“ grep”进行搜索。

  • Signal:信号:

Signals come under IPC mechanisms that are used for notification – notification can be process to process – notification can be system to process.

信号属于用于通知的IPC机制-通知可以逐个处理-通知可以逐个处理。

Kill is the command by which one process can send a signal to other.

Kill是一个进程可以向另一个进程发送信号的命令。

Syntax: kill <signal_name> <process_id>

语法:kill <信号名称> <进程ID>

Example:

例:

1)  Kill SIGINT 1234

1)杀死SIGINT 1234

2) Kill SIGQUIT 1234

2)杀死SIGQUIT 1234

Each signal has its own number.

每个信号都有自己的编号。

 Signal Name Signal Number Description
SIGINT 2 Issued if the user sends an interrupt signal (Ctrl + C)
SIGQUIT 3 Issued if the user sends a quit signal (Ctrl + D
信号名称 信号编号 描述
SIGINT 2 如果用户发送中断信号(Ctrl + C),则发出
SIGQUIT 3 如果用户发送退出信号(Ctrl + D

59. State the purpose of a signal?

59.陈述信号的目的?

Signals serves two important purposes:

信号有两个重要目的:

  • To make a process aware that a specific event has occurred使流程知道发生了特定事件
  • To force a process to execute a signal handler (customized/user) function included in user’s code.强制进程执行用户代码中包含的信号处理程序(自定义/用户)功能。

60. What is interrupt?

60.什么是中断?

An interrupt is a signal to the processor which can be generated by hardware or a software indicating an event that needs immediate attention. An interrupt indicates the processor to a high-priority condition requiring the interruption of the current task

中断是发给处理器的信号,可由硬件或软件生成,指示需要立即注意的事件。 中断表示处理器处于高优先级状态,需要中断当前任务

61. What is starvation and aging?

61.什么是饥饿和衰老?

Starvation:

饥饿:

Starvation is a resource management problem where a process is denied of resource or service for a long time or has been repeatedly denied services.

饥饿是资源管理问题,其中一个进程长时间拒绝资源或服务,或者一再被拒绝服务。

Aging:

老化:

This is a solution to starvation which involves gradually increasing the priority of processes that wait in the system for a long time.

这是一种饥饿的解决方案,它涉及逐步增加在系统中等待很长时间的进程的优先级。

The aging factor must increase the requests priority as time passes and must ensure that a request will eventually be the highest priority request (after it has waited long enough) and gets the chance to execute.

随着时间的流逝,老化因素必须提高请求的优先级,并且必须确保请求最终成为最高优先级的请求(在等待了足够长的时间之后)并有机会执行。

Note: It’s not same as deadlock.

注意:它与死锁不同。

Comment below if you have any queries related to above operating system interview questions and answers.

如果您有关于上述操作系统采访问题和答案的任何疑问,请在下面评论。

翻译自: https://www.thecrazyprogrammer.com/2017/03/operating-system-interview-questions-and-answers.html

操作系统 面试问题

操作系统 面试问题_操作系统面试问答相关推荐

  1. 操作系统饥饿现象_操作系统心得体会

    一.操作系统 1.基本概念 操作系统简称OS,是配置在计算机硬件上的第一层软件,它能够有效的组织和管理计算机系统中的硬件和软件资源,合理的组织计算机工作流程,控制程序的执行,并向用户提供各种服务功能. ...

  2. java 基础面试 英文_[Java面试] 面试java基础总结大全

    原标题:[Java面试] 面试java基础总结大全 基础知识: 1.JVM.JRE和JDK的区别: JVM(Java Virtual Machine):java虚拟机,用于保证java的跨平台的特性. ...

  3. 操作系统内存管理_操作系统6内存管理基础

    引言 花了一段时间才把之前的笔记整理了一部分,平时太忙也没啥时间.今天开始整理内存管理部分的,内存管理部分大致分为三部分笔记,第一部分就是本篇内存管理基础,第二部分是虚拟内存,第三部分高速缓存. 一个 ...

  4. 面试题目_经典面试题目「回溯算法」解数独

    解数独,理解二维递归是关键! 通知:我将公众号文章和学习相关的资料整理到了Github :https://github.com/youngyangyang04/leetcode-master,方便大家 ...

  5. 操作系统饥饿现象_操作系统常见面试题

    1.进程的常见状态?以及各种状态之间的转换条件? 就绪:进程已处于准备好运行的状态,即进程已分配到除CPU外的所有必要资源后,只要再获得CPU,便可立即执行. 执行:进程已经获得CPU,程序正在执行状 ...

  6. 面试题目_总结面试中 promise 相关题目的套路

    Promise 作为当下主流的异步解决方案,在工作中和面试中常常出现,尤其是在面试中,会弄个场景让你手写代码,这里给大家介绍五道比较有代表性的题目,以便熟悉一些套路. promise 简单介绍 先简单 ...

  7. 操作系统多线程实现_操作系统中的线程实现

    操作系统多线程实现 Each process has an address space. There is one thread of control in every traditional OS. ...

  8. 操作系统 系统开销比率_操作系统中的最高响应比率下一个(HRRN)调度

    操作系统 系统开销比率 操作系统中的HRRN调度是什么? (What is HRRN Scheduling in Operating System?) HRRN is the abbreviation ...

  9. 面试系统设计_系统设计面试问题–您应该知道的概念

    面试系统设计 You may have heard the terms "Architecture" or "System Design." These com ...

  10. 面试官面试前端_如何面试面试官

    面试官面试前端 by Aline Lerner 通过艾琳·勒纳(Aline Lerner) 如何面试面试官 (How to interview your interviewers) For the l ...

最新文章

  1. SVN的Windows和Linux客户端操作详解
  2. office 2007 验证失败的解决方法
  3. Spring AOP本质(7)
  4. Oracle 11g服务器与客户端卸载、安装
  5. Keras-训练可视化
  6. python list遍历 间隔_Python 列表(List) 的三种遍历(序号和值)方法
  7. 常量、变量;基本数据类型;input()、if、while、break、continue
  8. python调用接口失败_python调用软件com接口问题,python报错 -问答-阿里云开发者社区-阿里云...
  9. 使用jxls导出报错:Connot load XLS transformer please make sure a Transformer implementation is in classpath
  10. 监控提示服务器状态变更,服务器故障排除与状态监控
  11. 正点原子STM32F103 DMA代码例程魔改
  12. 基于Java在线学习系统设计与实现
  13. MapServer教程
  14. 国内外最顶级的8大plm项目管理系统
  15. html 图片循环轮播,如何在Web端实现动画切换效果一致的无限循环图片轮播?
  16. 《Python数据科学手册》—学习笔记
  17. 华硕重装后进入bios_重装系统以后,开机自动进bios,进不了系统怎么办
  18. Linux从入门到放弃 k8s 安装部署
  19. 最新AUTO病毒变种分析和解决方案
  20. php app接口id参数类型过滤,PHP开发APP接口---返回数据的封装类

热门文章

  1. Keil:Undefined symbol ......(referred from......)解决
  2. 公开课可下载资源汇总【转】
  3. *TEST 7 for NOIP 玄学解题 (150/300)
  4. MATLAB——更换主题颜色
  5. 1米6农村放牛娃的奋斗历程:从同济、港理工,到清华、伯克利大学!
  6. 指针变量占用的内存空间大小说明
  7. php开发的在线客服系统,全开源无加密,支持微信客服对接
  8. 从0开始学大数据(十四)
  9. BZOJ 2429: [HAOI2006]聪明的猴子 MST
  10. speedoffice(Excel)图片上怎么添加文字