System call in operating systems

  • Thread starter Thread starter Avichal
  • Start date Start date
  • Tags Tags
    System Systems
Click For Summary

Discussion Overview

The discussion revolves around the concept of system calls in operating systems, particularly in the context of programming in C. Participants explore the relationship between system calls, APIs, and programming statements, focusing on memory allocation and the execution of code.

Discussion Character

  • Conceptual clarification
  • Debate/contested
  • Technical explanation

Main Points Raised

  • One participant states that system calls provide services such as I/O operations and process management, and that C library functions like printf and scanf utilize these system calls.
  • Another participant explains that before a program runs, a compiler and linker prepare the working area and perform allocations, suggesting that at runtime, the statement "int x = 1" does not execute as written but rather passes the address of x to printf.
  • Some participants propose that the statement "int x = 1" allocates memory and assigns a value, implying it acts similarly to an API, which raises questions about the definitions of statements, system calls, and APIs.
  • One participant argues that after compilation, the executable contains startup code that allocates memory for the program, and that declaration and initialization statements do not require system calls, as they utilize static or stack memory.
  • There is a distinction made between function statements, which can be considered APIs, and other types of statements like assignment or control statements, which are not viewed as APIs.
  • A later reply mentions that typical C programs operate in user mode and can use system services through standard library functions, while device drivers may need to access kernel memory space using system APIs.

Areas of Agreement / Disagreement

Participants express differing views on whether programming statements like "int x = 1" can be classified as APIs. There is no consensus on the definitions and relationships between statements, system calls, and APIs, indicating ongoing confusion and debate.

Contextual Notes

Participants highlight the complexity of the relationship between programming constructs and system-level operations, noting that definitions may depend on context and interpretation. The discussion reveals a lack of clarity regarding when system calls are invoked and how they relate to higher-level programming abstractions.

Avichal
Messages
294
Reaction score
0
In an operating system, system call is an interface to provide services to the user. Services include I/O operations, process management etc.
Further, the C library provides me API above these system calls to make life easier. So printf, scanf internally use these system calls in the end.
Q.) Am I right till now?

So when I write a program say something like this:
Code:
#include <stdio.h>

int main()
{
    int x = 1;
    int y = 2;
    printf("%d\n", x+y);
    return 0;
}

I understand that printf is an API that helps me display stuff on the screen. Internally it uses some API.
But the lines "int x = 1" and "int y = 2", these also help me allocate memory and then assign some value to that memory. So in a way it is providing me service to access memory.
Q.) So is it also an API or a system call?
 
Technology news on Phys.org
Hi Avichal,

Before your program runs, a compiler and linker (or an interpreter) go to work to prepare the working area, do the allocations etcetera. So at run time there is no longer a statement int x = 1 executed. All that happens is that the printf service gets passed the address of x .

API stands for application programming Interface. Ususally we mean something at a higher level than hard-core system services (more oriented towards the application).
But a lot of it boils down to procedure calls, for the one as well as for the other.
 
The statement "int x = 1" allocates some memory and then assigns value 1 to it. This will of course require some system call to access the memory. So in a way, the statement "int x = 1" acts as a simpler way to access memory and assigning some value. This is similar to what an API does.
So isn't the statement "int x = 1" an API in a way.

I guess my confusions lies in the difference between statement, system call and API.
 
Avichal said:
The statement "int x = 1" allocates some memory and then assigns value 1 to it. This will of course require some system call to access the memory. So in a way, the statement "int x = 1" acts as a simpler way to access memory and assigning some value. This is similar to what an API does.
So isn't the statement "int x = 1" an API in a way.
No. After your program has been successfully compiled and linked, the executable that is produced contains startup code that executes before the first statement of your program is executed. Part of what happens in the startup code, I believe, is that the operating system makes several chunks of memory available to your program, such as stack memory and heap memory. In addition, programs use CPU registers, which can be considered another kind of memory.

The term "statement" can be broken down into several types, including declaration statements (e.g., int x = 1;), assignment statements (e.g., x = 3;), control statements (e.g., if (x > 2) ... ), function statements (e.g., printf("Done"); ), and others.

Function statements, such as the call to printf() above, can use standard library functions such as printf(), scanf(), sqrt(), and so on, or can use functions that you define in your code. These functions can be considered APIs, but assignment statements, control statements, aren't considered APIs, since they are basic constituents of the programming language in question.

A declaration and initialization statement (such as int x = 1;) doesn't require any system calls, I don't believe. Depending on where in the program this statement is, an appropriate sized block of memory in static memory or automatic (i.e., stack) memory is set aside, and is associated with the variable name, x. A string of bytes of the appropriate size containing the value 1 is copied to that memory location using nothing more complicated than a MOV instruction.
Avichal said:
I guess my confusions lies in the difference between statement, system call and API.
A typical C program is an application that operates in user mode. These kinds of programs can make use of system services by using the sys() standard library function. Device drivers, on the other hand, sometimes need to access kernel memory space. To do this, the drivers need to use system APIs to perform such tasks as creating and opening a file, and reading from or writing to a file.
 

Similar threads

  • · Replies 13 ·
Replies
13
Views
2K
  • · Replies 17 ·
Replies
17
Views
4K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 5 ·
Replies
5
Views
1K