0

getpid当我使用-std=c++11标志时,我想使用标头 sys/types.h、unistd.h(C 风格)中的函数,但之后我有:

“函数 getpid 无法解析”。

是否有某种解决方法或等效功能?

@编辑:

我再检查一次,它不是标志错误

头文件

#ifndef HEAD_H_
#define HEAD_H_

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

void test();

#endif /* HEAD_H_ */

头文件

#include "head.h"

void test()
{
    pid_t pid = getpid(); // Function 'getpid' could not be resolved
}

这很奇怪,因为我也在“干净”项目上进行了测试,完全没有问题。

主文件

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

int main()
{
      pid_t pid = getpid();

      return 0;
}

看起来我无法从 unistd 获得任何功能,因为

    char* a_cwd = getcwd(NULL,0);

也未解决

4

1 回答 1

4
#include <unistd.h>
#include <iostream>

int main()
{
  std::cout << getpid() << std::endl;
  return 0;
}

dgs@dhome:~/Develop/Test2$ g++ -std=c++11 getpid.cpp
dgs@dhome:~/Develop/Test2$ ./a.out
11980

dgs@dhome:~/Develop/Test2$ g++ --version
g++ (Debian 4.9.2-10) 4.9.2
于 2016-03-31T11:48:11.193 回答