7

The question stated below might not be technically correct(misconception) so it would be appreciable if misconception is also addressed.

Which ring level do the different *nix run levels operate in?

Ring tag not available.

peterph
  • 30,838

3 Answers3

10

Unix runlevels are orthogonal (in the sense "unrelated", "independent of" - see comments) to protection rings.

Runlevels are basically a run time configurations/states of the operating system as a whole, they describe what services are available ("to the user") - like SSH access, MTA, file server, GUI.

Rings are a hardware aided concept which allows finer grained control over the hardware (as mentioned in the wikipedia page you link to). For example code running in higher Ring may not be able to execute some CPU instructions.

Linux on the x86 architecture usually uses Ring0 for kernel (including device drivers) and Ring3 for userspace applications (regerdless of whether they are run by root or another ordinary or privileged user).

Hence you can't really say that a runlevel is running in some specific Ring - there are always1 userspace applications (at least PID 1 - the init) running in Ring3 and the kernel (Ring0).


1As always, the "always" really means "almost always", since you can run "normal" programs in Ring0, but you are unlikely to see that in real life (unless you work on HPC).

peterph
  • 30,838
  • when you say orthogonal do you mean Capability-based security? – Bleeding Fingers Oct 11 '13 at 19:29
  • 1
    No, orthogonal as in independent (meanings 3-5 on that wiktionary page). What made you think of Capability-based security? – peterph Oct 11 '13 at 19:32
  • true, cbs was diametrically opposite – Bleeding Fingers Oct 11 '13 at 19:34
  • 2
    High Performance Computing(HPC)? – Bleeding Fingers Oct 11 '13 at 19:50
  • 3
    Yes, High Performance Computing - the thing is, that normally applications make a lots of syscalls (requests to the kernel like accessing files, network etc.) and these incur a penalty for crossing witching execution between the Rings. Now, if you put your code into the same Ring as kernel, you can gain some performance on removing the need for these switches. Your code has to be written/tested more carefully, since it has access to things it normally hasn't and thus could potentially cause bigger disaster. :) – peterph Oct 11 '13 at 21:28
  • 2
    @peterph I think orthogonal is a fantastic word, but unfortunately, I think many may not know the word. Might be worth putting a simpler term in, at least in parentheses after orthogonal. – kurtm Oct 12 '13 at 00:20
  • would it be right to say the Minix shouldn't be used in such application? – Bleeding Fingers Oct 13 '13 at 15:40
  • "crossing witching execution"? – Bleeding Fingers Oct 13 '13 at 16:12
  • @hus787 "penalty for switching execution between different Rings", i.e. user space to kernel space transition (which actually has to happen twice for a syscall - in and out). As for Minix - if you mean because it is a microkernel, then it depends, but very likely so. You'd better ask another question, since I'm far from being an expert in kernel design. – peterph Oct 13 '13 at 16:19
  • To complete this HPC-discussion. Using Hypervisors like Xen in Paravirtualisation-Mode, the Guest-Kernel runns in Ring1. The Hypervisor-Kernel makes use of Ring0 and all the apps's are in Ring3. – Cutton Eye Apr 11 '18 at 10:43
0

The two concepts are completely unrelated. The system run level refers to the set of services that are running on the system, such as whether or not the gui desktop environment is running. Ring levels are a hardware protection mechanism on intel x86 processors that separate code into different privelege levels. Linux only uses rings 0 and 3 for kernel and user mode code respectively. Thus, all user mode processes, running when the system is in any run level execute in ring 3, until they make a call into kernel code, which transitions the cpu to ring 0.

psusi
  • 17,303
-2

From your own link:

In a monolithic kernel, the operating system runs in supervisor mode and the applications run in user mode. Other types of operating systems, like those with an exokernel or microkernel, do not necessarily share this behavior.

Some examples from the PC world:

Linux and Windows are two operating systems that use supervisor/user-mode. To perform specialized functions, user-mode code must perform a system call into supervisor mode or even to the kernel space where trusted code of the operating system will perform the needed task and return it back to user space.

So your answer would be 2. The supervisor (0) and the user (1).

Jeight
  • 2,603
  • -1 That's not really answer to the question Which ring level do the different nix run levels operate in?* – peterph Oct 11 '13 at 19:15
  • @peterph Your answer was the same ROOT and USER. I'll give that you explained better, but his answer was already in the link he gave. – Jeight Oct 11 '13 at 19:52
  • 1
    Yes, the answer is basically there - my complaint referred to your interpretation of it. Rings do not have anything to do with privileged (root) and unprivileged users, rather with kernel space/user space difference. And that's what my -1 has been for (I'm sorry that I haven't stated that explicitly). – peterph Oct 11 '13 at 21:33
  • @peterph Most people don't understand the difference between privileged/unprivileged users and kernel space/user space. Yes I should have put Kernel instead of supervisor, but I was just copying the quote from the article to make a point. I'm sorry that bothered you. I know you think I lot of new users are just copying and pasting from google without understanding what they are saying (I read your post), but maybe you should review someones question/answer history before jumping to conclusions. – Jeight Oct 11 '13 at 21:54
  • 1
    No need for reviewing anyone's history - I'm not arguing ad personam. It is the answer in its current form that in my opinion is wrong. – peterph Oct 11 '13 at 22:22