1

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!

prcastro
  • 2,178
  • 3
  • 19
  • 21
  • 5
    `man ` is a very important command, used like for example `man fork`. – Some programmer dude Jan 21 '14 at 18:23
  • 1
    As Joachim mentioned, you need to read the docs - different APIs need different headers. Also you may need to define "feature macros" that indicate to the system which specific set of APIs you want activated. See `man feature_test_macros`. You'd probably be OK to start with `-D_GNU_SOURCE`, as that includes pretty much everything. – Michael Burr Jan 21 '14 at 18:33
  • 2
    The master to the man-pages coming with Linux is here: http://man7.org/linux/man-pages The one for `fork()` is here: http://man7.org/linux/man-pages/man2/fork.2.html The POSIX reference: http://pubs.opengroup.org/onlinepubs/9699919799/functions/fork.html – alk Jan 21 '14 at 18:46
  • Also study the source code of simple free software shells. – Basile Starynkevitch Jan 21 '14 at 18:56

1 Answers1

1

A google search of man fork will show the linux man page and it indicates that it needs:

#include <unistd.h>
woolstar
  • 5,063
  • 20
  • 31