简体   繁体   中英

Where does task_struct get initialized in the Linux kernel?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM