【问题标题】:what is the variable type of PID in PROCESS SYSTEM CALL?PROCESS SYSTEM CALL中PID的变量类型是什么?
【发布时间】:2015-03-18 00:09:39
【问题描述】:

这是创建子进程的部分代码

#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>

main()
{
  pid_t pid;

pid_t 被声明为 pid 的变量。但是值和整数一样。

  int x = 5;
  pid = fork();

fork() 是创建子进程的函数。

  x++;

  if(pid<0)
  {
    printf("process creation error");
    exit(-1);
  }
  else if(pid==0)
  {
    printf("Child Process");
    printf("\nChild Process ID is %d",getpid());
x++;
    printf("\nValue of X is %d",x);  
    printf("\nProcess id of parent is %d",getppid()); 
  }

【问题讨论】:

    标签: c process operating-system fork pid


    【解决方案1】:

    变量pid的类型是pid_tpid_t 本身的定义方式取决于操作系统。在 Linux 中它是这样定义的:

    typedef __pid_t pid_t;
    

    __pid_t 最终被定义为int。见GCC declarations: typedef __pid_t pid_t?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-15
      • 1970-01-01
      • 2015-08-22
      相关资源
      最近更新 更多