Implicit Function Declaration in C UNIX

The following code displays a warning about the implicit declaration of the getpgid function. I only know his warning, but his class and professor want us to consider warnings as errors. So help please.

I also included the corresponding header file, so I have no idea what is wrong:

#include <unistd.h>

pid_t pid, pgid;

if ((pgid = getpgid(pid)) < 0) {
      app_error("Failure to get process group ID");
}
+3
source share
4 answers

On the man page :

Requirements for function check macros for glibc (see feature_test_macros(7)):

getpgid():
      _XOPEN_SOURCE >= 500 || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
      || /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L
+4
source

Assume all elision: pid_t is undefined. You need both

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

Otherwise, you will not get what you think you are getting.

, . , ( ) , , .

#include <unistd.h>
#include <stdio.h>
int main() {
     pid_t pid, pgid;
     if((pgid = getpgid(pid)) < 0) {
          puts("Oops.");
     }
     return 0;
}

:
 1. . . .
 2. , .

, , .

+2

/ , . , . , - .

, getpgid , , POSIX getpgrp(void). ( ), .

+1

"getpgid", -

0

Source: https://habr.com/ru/post/1770226/


All Articles