Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implicit declaration of function ‘wait’

Tags:

c

wait

pid

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");
  }
}
like image 769
AyeJay Avatar asked Jan 26 '17 23:01

AyeJay


2 Answers

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

  #include <sys/types.h>
  #include <sys/wait.h>
like image 108
P.P Avatar answered Oct 18 '22 21:10

P.P


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

like image 33
Barmar Avatar answered Oct 18 '22 20:10

Barmar