English 中文(简体)
福特
原标题:Fork implementation

• 如何用墨电码书写。 我想了解一些细节,说明一项职能如何能够恢复两个不同的价值观,以及两个不同的进程。 简言之,我们想知道如何实施“k”系统?

问题回答

Carl s的回答是巨大的。 我要补充的是,在许多操作系统中,回报值在一份登记册中获得通过。 在x86的建筑中,这一登记册可能是轴心,在ARM中,这一登记册可能为R0,等等。

每个过程都有一个过程控制区(PCB),该区储存一些中断、停产或例外时的登记价值,并将控制权交给监督厅。 下一次进程安排,登记册的数值由协委会恢复。

如今,当出现危机时,本组织可以做到:

 child_process->PCB[return_value_register] = 0;
 parrent_process->PCB[return_value_register] = child_pid;

因此,当这些过程重新排期时,每个过程的回报价值不同。

例如,请见xv6 执行k 。 在那里,家长程序仍然处于运行状态,因此,它采用简单的返回声明来收回父母的返回价值。 但它将幼儿生存和发展登记的价值定为0,因此,当儿童进程被安排时,它就将零视为回报价值:

// Clear %eax so that fork returns 0 in the child.
np->tf->eax = 0;

请注意,返回后0还将编纂成“移动经济”,0。

<>Update: 我刚刚为我正在做的一位非洲顾问团(k)执行。 可查阅源代码

你说,它是一个系统呼吁,这充分解释了它。 运行系统需要做所有工作,运行系统可以做很多事情,不管它想要做什么,都不属于你的方案或你以什么语言重新实施的方案。 这里,可以简单地说明如何做到这一点:

  1. Program calls fork() system call
  2. Kernel fork system call duplicates the process running the program
  3. The kernel sets the return value for the system call for the original program and for the duplicate (PID of the duplicate and 0, respectively)
  4. The kernel puts both processes in the scheduler queue
  5. As each process is scheduled, the kernel returns to each of the two programs.

http://en.wikipedia.org/wiki/Version_6_Unix” rel=“nofollow”>Unix V6各大学源代码手册,由Ken Thompson和Dennis Ritchie自己作了说明,说明双重回归是如何实际运作的。 评注结尾处的句子如下:

预计你们不会理解这一点。





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签