0
votes

In user-space we can create a process by executing program or calling fork inside a program, Kernel will create process descriptor(task_struct) for each user-space process.

In kernel space is there any any concept called process, if so how they will be created?

As per my understanding kernel threads will be created in kernel space using kernel_thread() etc, kernel_thread() is internally calling do_fork(), so kernel threads also represented using task_struct?

If both user-space process and kernel space threads are represented using task_struct, then how scheduler will schedule the user-space process and kernel space thread?

2
task_struct controls a single thread (kernel or user space), not a process. - n. 1.8e9-where's-my-share m.
task_thread controls a single thread means, everything is a thread in user-space and kernel space? How process and thread differs in user-space? - user3693586
Processes and threads in user-space diffen in what they share. Threads share FDs and memory (and a few other things), while processes do not (unless explicitly shared). There is only one kernell memory space, so there is no sense in talking about kernel processes, only kernel threads. - rodrigo

2 Answers

2
votes

Yes, they all handled through task_struct.

Critical kernel threads have RT ("Real-Time") scheduler class which have priority over CFS scheduler that is usually used for user-space threads. . Just check your ps:

# ps ax --format uname,pid,ppid,tty,cmd,cls,pri,rtprio | egrep '(FF|RR)'

(kernel threads are shown in square brackets)

However, as you can see many kernel threads have TS scheduler. I do not think that there is reason make all kernel threads realtime. For example, you can defer writeback to a disk over emotional scene shown by VLC player.

1
votes

Moreover I suppose that even POSIX threads which share the memory segments (e.g. heap, global varaibales ) with another threads, are handled by task_struct as well.