0

Is it possible that one process is running in kernel mode and another in user mode at the same time?

I know, it's not a coding question but please guide me if someone knows answer.

Harshil Shah
  • 142
  • 2
  • 3
  • 13

3 Answers3

2

For two processes to actually be running at the same time, you must have multiple CPUs. And indeed, when you have multiple CPUs, what runs on the different CPUs is very loosly coupled and you can definitely have one process running user code on one CPU, while another process runs kernel code (e.g., doing some work inside a system call) on another CPU.

If you are asking about just one CPU, in that case you can't have two running processes at the same time. But what you can have is two runnable processes, which mean two processes which are both ready to run but since there is just one CPU, only one of the can actually run. One of the runnable processes might be in user mode - e.g., consider a long-running tight loop that was preempted after its time quota was over. Another runnable process might be in kernel mode - e.g., consider a process that did a read() system call from disk, the kernel sent the read request to the disk, but the read request completed so now the process is ready to run again in kernel mode and complete the read() call.

Nadav Har'El
  • 11,785
  • 1
  • 24
  • 45
  • So it means, if we have only one CPU, there is only one process either in kernel mode or in user mode, right? – Harshil Shah Apr 29 '19 at 23:42
  • "there is only one process" is ambiguous. There can be a hundreds processes, and each can be sleeping in user mode (i.e., preempted in the middle of the computation) or in kernel mode (a system call couldn't yet complete, and put the process to sleep). But of course on a single CPU only one of these processes can actually **run** at any one time. – Nadav Har'El Apr 30 '19 at 08:33
1

Yes, it is possible. Even multiple processes can be in the kernel mode at the same time.

Just that a single process cannot be in both the modes at the same time.

Yash Sodha
  • 713
  • 3
  • 13
  • Can a single process be in both at the same time if it uses threads? – Jack Humphries Apr 30 '19 at 07:22
  • Jack, a "thread" and a "process" are for most intents and purposes the same concept as far as the kernel is concerned, with some special exceptions for historic reasons. Two different threads, even if spawned from the same process, run independently, and run or don't run system calls ("kernel mode") independently. – Nadav Har'El Apr 30 '19 at 08:35
0

correct me but i suppose there is no any processes in kernel mode , there are only threads.

Alex
  • 837
  • 8
  • 9