5

The book 'Understanding Linux Kernel' says that 'for something abstract such as math functions, there may be no reason to make system calls'. Can any one please explain how is a system call not required in math functions? Isn't the CPU involved in mathematical operations? Can anyone give an example of such a program?

6

I don't have that book to check, but I assuming its using the normal meaning of system calls, then a system call is a call into the kernel to perform some operation the hardware considers privileged, or is unaware of. This is used to enforce permissions, etc. on the system. So you need to make a system call to (among many other things):

  • read from a file (the kernel must check that the permissions allow you to read from said file, and then the kernel carries out the actual instructions to the disk to read the file)
  • signal a process (processes do not exist as far as the hardware is concerned, they are an abstraction provided by the kernel, etc.)
  • obtain additional memory (the kernel must make sure you don't exceed the ulimit, make sure two processes don't claim the same RAM, etc.)

Math is not one of those things. Typically, it requires no intervention from the kernel.

  • I will appreciate if you can suggest me some good links and papers that explain further on this topic. – Jay Jan 2 '14 at 17:09
  • @Jay you might want to start with Wikipedia's article on System Calls for an overview... – derobert Jan 2 '14 at 17:11
  • If math functions does not require intervention from the kernel, how does the application program interacts with the CPU? I am sure it does not directly interact. – Jay Jan 2 '14 at 17:19
  • 2
    @Jay Directly. The CPU executes instructions from memory. The program consists of instructions, stored in memory. – derobert Jan 2 '14 at 17:20
  • Thanks for the quick replies. You cleared a lot of confusion. – Jay Jan 2 '14 at 17:30
3

A "system call" is a call to a kernel function. This is needed for functionality managed by the kernel, like accessing devices. For "normal" operation like adding numbers no help from the kernel is needed. Therefore calling a library which is only computing stuff, no call to kernel space is needed, too.

You can use strace to show all the system calls of a given program.

  • The first line of the chapter 10. System Calls in the book mentioned above says "Operating systems offer processes running in User Mode a set of interfaces to interact with hardware devices such as the "CPU", disks and printers.' – Jay Jan 2 '14 at 16:40
  • @Jay For the purposes of that definition, running code doesn't count as "interacting". I think something like getcpu() is what's meant. – mattdm Jan 2 '14 at 16:49
3

Executing a process executes CPU instructions by definition. There are a few CPU instructions that can only be executed in a privileged mode, mostly instructions related to accessing hardware outside the CPU including the RAM or to modifying some configurations. The kernel is executed in privileged mode, ordinary processes are executed in unprivileged mode. The details of what “privileged mode” means depends on the CPU architecture.

Purely computational instructions such as integer operations and floating point operations do not require any privileged access, so they can be executed by ordinary processes.

When a process wants to perform an operation that requires privileges, it has to invoke some kernel code to do it. There is a special CPU instruction that simultaneously switches the CPU to privileged mode and branches to a predefined address in memory. In a unix-like operating system (and in most OSes in general), this action is called a system call.

Unix provides isolation between processes, so it sets up the processor (specifically, the MMU) in such a way that each process can only access its own memory, and not the memory of other processes or the kernel. (Almost) any action that could affect other processes or that involves access to hardware outside the main CPU goes through the kernel and hence requires a system call. This includes access to files and hardware devices, networking, inter-process communication, privilege and memory management, etc.

You can see the documentation for the system calls on your system in section 2 of the manual. You can see what system calls a process makes by launching it via truss on Solaris and FreeBSD, strace on Linux, or equivalents under other unix variants.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.