Implicit declaration of function ‘wait’

AyeJay picture AyeJay · Jan 27, 2017 · Viewed 50.3k times · Source

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");
  }
}

Answer

P.P picture P.P · Jan 27, 2017

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

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