1

This is a Computer Science question about programming languages and operating systems.

My question is, what are the basic interactions between a programming language and operating systems? I do have a idea about the IFE cycle of the operating systems but not sure how the programming languages fit in.

I have read this post but it is not of any help

Questions on how compiled programs interact with the operating system

Edit:

By Programming Language, I mean to include their respective compiler/VM

Community
  • 1
  • 1
srnvs
  • 997
  • 2
  • 10
  • 22

2 Answers2

3

At the machine code level, the program must make a system call.

Different processors have different methods available to make system calls. Each operating system must choose a system calling convention for a given processor architecture. For example, for x86 processors, Linux used to use software interrupt instruction INT 0x80 to execute its system calls -- but (per the comment below) it now uses a SYSENTER instruction, which was introduced to the architecture specifically for that purpose.

System calling conventions are not really specific to the programming language as such, but they are necessarily written into the most fundamental standard libraries for a given language and operating system.

comingstorm
  • 25,557
  • 3
  • 43
  • 67
  • 3
    While your answer is sensible in general, I'd make two remarks: 1) the concept of system calls is found on many (most?) mainstream kernels but I'd not swear by it as both funky kernels and queer hardware platforms exist; 2) Linux and Windows use `SYSENTER`/`SYSEXIT` on x86/amd64 since ages -- Linux uses a [specially injected VDSO](http://www.trilithium.com/johan/2005/08/linux-gate/) for this, and Windows has a pretty similar infrastrusture in its `ntdll.dll` which is mapped into the address space of any process. – kostix Apr 04 '13 at 23:52
  • Thanks for the link -- it's been a while since I looked at this kind of stuff, I will edit my answer accordingly. At any rate, any kind of OS will have *some* kind of syscall convention -- even if it's *only* a convention because it's on an embedded platform without hardware protection... – comingstorm Apr 05 '13 at 00:11
  • comingstorm and @kostix does that mean that the compiler/vm runs as a privileged application (similar to how the virtual box runs)? – srnvs Apr 05 '13 at 03:39
  • @hld619, of course not! Specifically, the system calls (in hardw. architectures which implement privilege separation) provide kind of "gates" which allow unprivileged processes to perform certain (otherwise privileged) operations *on behalf of the kernel* which controls these processes. IOW, when a process "is in" a system call, it's executing the kernel code in the context of the kernel; when the system call exits, the control is passed back to the process's own code. – kostix Apr 05 '13 at 08:04
  • @hld619, and note that virtualization is completely another thing which greatly complicates matters (especially since there are different types of it) so if you learned the word "VM" in that SO answer I linked to, please unlearn it: the person employing this metaphor tried to stress that a user-space process is "contained" and has no direct access to devices, physical memory etc -- all this access is mediated by the kernel, and hence yes, the real world is kind of "virtualized" for processes by their kernel. But this had nothing to do with what is called "virtualization" in today's magazines. – kostix Apr 05 '13 at 08:11
  • @kostix, after reading your answers multiple times, I think I am getting a gist of what you intend to say. But one doubt that remains is `do the compilers run in kernel mode or in user mode?`(I brought up the virtualization stuff because I know that VMs run in kernel mode to achieve the privileged access) I think this question sums up my doubts exactly. – srnvs Apr 05 '13 at 11:22
  • Compilers typically run in user mode. A compiler doesn't require any special privilege or access -- from the OS point of view, all it does is read and write ordinary files! – comingstorm Apr 05 '13 at 16:54
  • @hld619, which sort of compilers do you mean -- ahead-of-time, like those for C++, or just-in-time, like those built into the Java and .NET VMs? Both types of compilers run unprivileged, but to properly answer your "final question" we need to know what you're talking about. – kostix Apr 05 '13 at 17:02
  • @kostix The VMs that I was referring to is with respect to virtualization(read Virtual Box). The compilers that I am doubtful about are the ones that have VMs(read JVM and .NET VM). I do know that those two are two completely different entities. I was comparing them to VMs since as I previously mentioned, they run in kernel mode(read Virtual Box) and was wondering if the programming VMs(read JVM) also run in kernel mode to achieve what they want. Anyways, your comment answers my question. Thank you so much for your time :) – srnvs Apr 05 '13 at 20:33
  • 1
    @hld619, by the way, an interesting example of an *in-kernel* compiler and the associated runtime is [BPF](http://en.wikipedia.org/wiki/Berkeley_Packet_Filter) which is found in Linux and FreeBSD kernels at least. – kostix Apr 05 '13 at 23:18
-2

A programming language does not interact with the operating system because it's a language, an abstract idea, it is not an (inter)actor of any kind. It's simply a system that can be used to express programs and algorithms using its lexical elements, conforming to its grammar and rules and so on.

What can interact with the OS is programs. Interpreters and compilers of a programming language, which are programs, interact with the OS. Compiled programs interact with the OS. Languages do not. They aren't programs.

Alexey Frunze
  • 61,140
  • 12
  • 83
  • 180
  • 2
    Thanks Alex, I meant the underlying Compilers itself or Interpreters itself. When I said Programming Languages, I assumed that compilers/interpreters are a part of it – srnvs Apr 04 '13 at 22:08
  • Compilers and interpreters *embody* in code the respective languages, the abstract ideas. – Alexey Frunze Apr 04 '13 at 22:11
  • At the very basic level all programs need I/O. They are useless otherwise. The OS lets programs do I/O. That's as basic as you can get. – Alexey Frunze Apr 04 '13 at 22:13
  • 2
    You can express interactions with OS in a programming language - and in this sense programming languages do interact with OS. This is mostly semantics, and the intention of the OP is quite clear here. – Andrew Savinykh Apr 04 '13 at 23:44
  • 1
    @zespri If you ask the wrong question, you don't get the right answer to what you really had in mind. – Alexey Frunze Apr 05 '13 at 00:08
  • The quintessential pedantic answer. – cmhteixeira May 21 '22 at 20:34