Issue
Is there a function that gets called to initialize (at least some) values of task_struct
? Or is there any other function that gets called upon task (specifically, user-space process) creation?
Solution
Since the only way to create a new process in Linux is through the clone()
syscall (or other variants like fork()
), there is no real function to "create a new task" from scratch, but there sure is a function to duplicate an existing task, applying the needed modifications. The function used for this is copy_process()
, which uses dup_task_struct()
to duplicate the associated struct task_struct
.
There is however one special exception to this rule, the init process (the first process created after booting) is created by the kernel itself (every other process is then created by init or by some child of init through clone()
+ execve()
). The task_struct
for the init task is statically defined at compile time (see here). You can look at this other answer if you want to know more.
Answered By - Marco Bonelli Answer Checked By - Katrina (WPSolving Volunteer)