简体   繁体   中英

What do I have to include on a C program to use POSIX system calls?

I'm learning about operating systems on The MINIX Book (Tanembaum), and one of the exercises I went through is to build a VERY simple shell.

For this, the book provides this piece of code:

#define TRUE 1

while (TRUE) {
   type_prompt();
   read_command(command, parameters);

   if (fork() != 0) {
      waitpid(-1, &status, 0);
   } else {
      execve(command, parameters, 0);
   }
}

This is not the entire C program (obviously) and I need to declare some variables and write some functions by my own. But fork() , for example, is a system call (as said in the book, it should be POSIX compatible).

What #include directives my program should have to use them, assuming I am compiling this program on MINIX already (and all other functions that I wrote are in this same .c file)? How does it work to use Linux system calls on C programs?

Thanks!

谷歌搜索man fork将显示linux手册页,它表明它需要:

#include <unistd.h>

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