> For the complete documentation index, see [llms.txt](https://eric-lo.gitbook.io/lab4-process/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://eric-lo.gitbook.io/lab4-process/wait/wait-system-call.md).

# Wait System Call

```c
pid_t wait(int *status);
```

In order to suspend the parent and handle the child properly, the `wait` system call is necessary.

```c
/* Wait/wait.c */
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

int main(int argc,char *argv[])
{
    while(1)    
    {
        printf("Press Enter to execute ls");
        while(getchar() != '\n');
        if(!fork())
        { 
            execl("/bin/ls","ls",NULL); 
        } 
        else 
        { 
           wait(NULL); 
        } 
   }
    return 0;
}
```

`wait()` takes one parameter for storing the status of the child process, for example, whether it is terminated or suspended. If you are not interested, just put `NULL` as the parameter.

This is a similar program in [Problem 2](/lab4-process/wait/zombies.md). However, this can get rid of zombies!
