简体   繁体   中英

How can I express wait(NULL) without getting compilation warning?

If I compile my program with cc then it works. But I must compile using gcc -pedantic -Wall -ansi -O4 . Then I get a warning for the statement wait(NULL)

miniShell.c: In function ‘main’:
miniShell.c:84:13: warning: implicit declaration of function ‘wait’ [-Wimplicit-function-declaration]
             wait(NULL);
             ^

Can I rewrite it to please the compiler?

From the Linux Programmer's Manual :

WAIT(2)                    Linux Programmer's Manual                   WAIT(2)

NAME
       wait, waitpid, waitid - wait for process to change state

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

       pid_t wait(int *status);

So add those two #include s to use wait() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM