而我学习操作系统当然,我不明白为什么下面的代码的输出类似这样的任何人都可以解释这个输出(操作系统)?
代码:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
int main (int argc, const char * argv[]) {
int value = 5;
pid_t pid = fork();
printf("pid = %d \n",pid);
if (pid == 0){
value+=15;
printf("Value ch :%d \n",value);
}
else {
if (pid > 0) {
wait(NULL);
printf("Value pr :%d \n",value);
exit(1);
}
}
return 0;
}
OUTPUT:
run
[Switching to process 24752]
Running…
pid = 24756
pid = 0
Value ch :20
Value pr :5
如果孩子值变成20为什么从孩子返回后值= 5
如何打印内存地址? – 2010-11-19 15:53:06
@ Bobj-C:你可以使用'printf(“%p”,(void *)&value)打印一个地址;' – 2010-11-19 16:03:19
我在子代和父代PID的相同输出中添加一个十六进制值的代码? – 2010-11-19 16:07:35