0

I would like to use getpid function from headers sys/types.h, unistd.h (C style) when I am using -std=c++11 flag but after that I have :

"function getpid could not be resolved".

Is there is some kind of workaround or equivalent function?

@Edit:

I check it one more time and it is not flag fault

head.h

#ifndef HEAD_H_
#define HEAD_H_

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

void test();

#endif /* HEAD_H_ */

head.cpp

#include "head.h"

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

and this is weird because I also make test on "clean" project and there was no problem at all.

main.cpp

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

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

      return 0;
}

It looks like I am not able to get any function from unistd, because

    char* a_cwd = getcwd(NULL,0);

is also unresolved

user3626411
  • 188
  • 2
  • 3
  • 15

1 Answers1

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
dgsomerton
  • 105
  • 5