Implicit Declaration of Function ‘Wait’

Implicit Declaration of Function ‘Wait’

I am getting a warning > Implicit declaration of function ‘wait’ < and when I run the program it works correctly, I would like to understand why I am getting this warning?

Thanks in advance

Edit: I forgot to add the library included

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


void create (char* program, char** arg_list)
{
  /* put your code here */
  pid_t childPid;
  int status;

  if((childPid = fork()) < 0){
    printf("Failed to fork() --- exiting...\n");
    exit(1);
  }
  else if (childPid == 0){ // --- inside the child process
    if(execvp(program, arg_list) < 0){ // Failed to run the command
      printf("*** Failed to exec %s\n", program);
      exit(1);
    }
  }
  else{ // --- parent process
    while(wait(&status) != childPid)
      printf("...\n");
  }
}
1

2 Answers

You are probably missing the headers for wait(2):

  #include <sys/types.h>
  #include <sys/wait.h>
5

You need to put:

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

at the top of the program to get the declaration of the function.

This is shown in the man page

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

James H. Sterling
Author

James H. Sterling

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.