我当时正在阅读Linux开发,并试图理解fork()情况下的进程地址空间语义。当我在Kernel v2.6的上下文中阅读时,以及在新版本中,任何子版本或父版本都可能先运行,但我对以下内容感到困惑:
Back in do_fork(), if copy_process() returns successfully, the new child is woken up
and run. Deliberately, the kernel runs the child process first. In the common case of the
child simply calling exec(
我有一个任务是用fork做一个矩阵乘法,使用共享内存,然后将时间结果与没有fork的乘法进行比较,所以这是没有fork的乘法:
int matrizA[Am][An];
int matrizB[An][Bp];
//here i fill the matrix from a .txt file
int matrizR[Am][Bp];
int a,b,c;
for (a=0; a < Am; a++){
for (b = 0; b < Bp; b++)
{
matrizR[a][b] = 0;
for (c=0; c<An;
在Gnu系统上,我可以编写一个像dies_ok()这样的C宏,它将派生一个新进程,运行一段代码,之后它可以写入它没有退出的共享内存,然后在父进程中我可以确定它是否退出。这对于测试很有用:
dies_ok({int x = 0/0;}, "can't divide by zero");
lives_ok({int x = 3/7;}, "this is a perfectly fine statement");
dies_ok({abort();}, "abort kills the program");
有没有办法在没有fork函数的MS
来自
Under Linux, fork() is implemented using copy-on-write pages, so
the only penalty that it incurs is the time and memory required
to duplicate the parent's page tables, and to create a unique
task structure for the child.
因此,在这个例子中:
#include <stdio.h>
#include <stdlib.h>