printf(“before fork.\n”); if( (pid = fork() )<0) {
printf(“fork error \n”); exit(0); } else if ( pid == 0 ) printf(“Child is printing. \n”); else printf(“Parent is printing .\n”); exit(0); /*both parent and child execute*/ }
#include <sys/types.h>
#include <unistd.h>
int globa = 4;
int main(void)
{ pid_t pid;
int vari = 5 ;
printf(“before fork.\n”);
(1) 用 户 数 据 的 保 存 : 包 括 正 文 段 (TEXT), 数 据 段 (DATA,BSS), 栈段 (STACK), 共享内存段(SHARED MEMORY)的保存.
2020/9/24
13
(2)寄存器数据的保存: 包括 PC(program counter,指向下一条要执行的指 令的地 址), PSW(processor status word,处理机状态字), SP(stack pointer,栈指针), PCBP(pointer of process control block,进程控 制块指 针), FP(frame pointer,指向栈中一个函数的local变量的首 地 址), AP(augument pointer,指向栈中函数调用的实参位置), ISP( interrupt stack pointer,中断栈指针), 以及其他的通用寄存器等.