image.png

简介

  1. int main()
  2. {
  3. int n = 0x00;
  4. int pid = fork();
  5. if (pid == -1)
  6. return -1;
  7. n = 10; // 修改两个进程共同都握有的一个页,此时将会触发cow
  8. if (pid)
  9. {
  10. printf("I am father, my pid is %d\n", getpid());
  11. return 0;
  12. }
  13. else
  14. {
  15. printf("I am child, my pid is %d\n", getpid());
  16. return 0;
  17. }
  18. }

参考资料

Linux fork那些隐藏的开销