1
$\begingroup$

Question on operating system If we execute kernel programs in the user mode and user programs in kernel mode what are some consequences

$\endgroup$
1
$\begingroup$

Assuming a monolithic kernel like Linux, there just are no "kernel programs", every in-kernel thread is just a function running in the kernel's address space. If you copy that and place it in a userland program (given the correct environment in terms of available data structures and functions to call) it will work fine as long as it doesn't invoke any privileged operations. Any of those will give some sort of exception.

Placing a userland program into the kernel would mean to add a lot of infrastructure provided by the operating system: in C's terms, standard input and output, the contents of the standard C library and any others in use. Using a snippet of userland code in the kernel will work just fine, as long as any infrastructure/environment called upon is provided.

Kernel code and userland code are the exact same instructions (but the kernel has access to some privileged operations and registers that userland can't use).

$\endgroup$
1
  • $\begingroup$ Many modern operating systems have the possibility of running the kernel as a user process, for various use cases: kernel development, testing, simulation, containerization etc. Some examples are User Mode Linux and the the DragonFly BSD Virtual Kernel. $\endgroup$ – Jörg W Mittag Mar 26 at 20:31

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.