If you're in a university computer science program, it is likely that you will be required to take some courses relating to operating systems. In a more advanced course, the MINIX operating system may be used as an example, and you may be assigned projects that involve creating new system calls and system commands-- modifying and adding to the source code. I recently completed such a course, so I know how difficult it can be to know where to begin. I can't say I'm an OS expert, but hopefully this can guide you in the right direction.

A system call is a function that allows a user program to communicate with the OS. An example of an existing system call on UNIX-based systems is chmod. (So that you aren't confused, I should note that it is also a system command.) In C, the chmod system call would be made thus:

   if (chmod("/home/al-kahina/secrets.txt", S_IRUSR|S_IWUSR) != 0) {
      printf("chmod error: %s (%d)\n", strerror(errno), errno);
      return 1;
   }

If an error does not occur, this will result in the file /home/al-kahina/secrets.txt being given the permissions 0600, which means that the owner of the file may read and write but not execute the file and everyone else has no access to the file.

In an OS course project, you may be asked to create a system call that can be used in a similar way. You will need to modify the source code thus, assuming your system call is called sys_call (also, unless otherwise stated, all your code will be in C):
There may be other things you'll need to add depending on what sys_call does, but this is a general list of things to add to the source code. Keep in mind that it may be more complicated in certain circumstances. For example, if a system call is meant to manipulate the protection bits of a file, there will need to be a do_sys_call function somewhere under the vfs directory and an fs_sys_call function under the mfs directory, and mfs has a separate call vector to deal with as well. For cases like that, and whenever in doubt, use existing system calls that do similar things as examples.

System commands can be called from the command line, often with parameters. An example of this is ls, which lists the contents of a directory. They do not necessarily have to communicate with the OS, but most do, and if you are assigned a project involving creating a system command, it probably will be requesting a service from the OS. You will probably be required to make a system call to do the actual work. After you create the system call like above, it is very simple to wrap it in a system command. The system command is created thus, assuming your system command is called sys_command: And that's it! If you follow the example of other system commands, when MINIX is recompiled, the sys_command executable will be created in the /bin/ directory with the other system commands, and you will be able to use it from the command line.

Last updated May 7, 2016

al-Kahina CLI Programs Home