当前位置:   article > 正文

一文搞懂Linux内核进程原理及系统调用机制_kernel 进程

kernel 进程

进程四要素

  • 有一段程序代其执行
  • 有进程专用的系统堆栈空间
  • 在内核有task_struct数据结构
  • 进程有独立的存储空间,拥有专有的用户空间
    如果具备前三点缺少第四条,称为“线程”;如果完全没有用户空间,称为“内核线程”;如果共享用户空间,称为“用户线程”。

进程生命周期

  • 运行
  • 等待:可以运行,没有得到许可。调度器可以在下一个任务切换时选择该进程。
  • 睡眠:等待一个外部事件。
  • 转换关系:

内核资料直通车:最新Linux内核源码资料文档+视频资料

学习直通车:Linux内核源码/内存调优/文件系统/进程管理/设备驱动/网络协议栈

task_struct数据结构

进程描述task_struct数据结构

  1. struct task_struct {
  2. // 进程状态
  3. volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
  4. void *stack; // 指向内核栈指针
  5. atomic_t usage; // 有几个进程使用此结构
  6. unsigned int flags; /* per process flags, defined below */
  7. unsigned int ptrace; // ptrace系统调用 实现断点调试 跟踪进程运行
  8. // 条件编译多处理器用到
  9. #ifdef CONFIG_SMP
  10. struct llist_node wake_entry;
  11. int on_cpu;
  12. unsigned int wakee_flips;
  13. unsigned long wakee_flip_decay_ts;
  14. struct task_struct *last_wakee;
  15. int wake_cpu;
  16. #endif
  17. // 运行队列和进程调试相关程序
  18. int on_rq;
  19. int prio, static_prio, normal_prio; //关于进程调试
  20. unsigned int rt_priority; //优先级
  21. // 关于进程
  22. const struct sched_class *sched_class;
  23. struct sched_entity se;
  24. struct sched_rt_entity rt;
  25. // 结构体链表
  26. #ifdef CONFIG_CGROUP_SCHED
  27. struct task_group *sched_task_group;
  28. #endif
  29. struct sched_dl_entity dl;
  30. #ifdef CONFIG_PREEMPT_NOTIFIERS
  31. /* list of struct preempt_notifier: */
  32. struct hlist_head preempt_notifiers;
  33. #endif
  34. // 块设备I/O的跟踪工具
  35. #ifdef CONFIG_BLK_DEV_IO_TRACE
  36. unsigned int btrace_seq;
  37. #endif
  38. // 进程调试策略相关的字段
  39. unsigned int policy;
  40. int nr_cpus_allowed;
  41. cpumask_t cpus_allowed;
  42. // RCU同步原语
  43. #ifdef CONFIG_PREEMPT_RCU
  44. int rcu_read_lock_nesting;
  45. union rcu_special rcu_read_unlock_special;
  46. struct list_head rcu_node_entry;
  47. struct rcu_node *rcu_blocked_node;
  48. #endif /* #ifdef CONFIG_PREEMPT_RCU */
  49. #ifdef CONFIG_TASKS_RCU
  50. unsigned long rcu_tasks_nvcsw;
  51. bool rcu_tasks_holdout;
  52. struct list_head rcu_tasks_holdout_list;
  53. int rcu_tasks_idle_cpu;
  54. #endif /* #ifdef CONFIG_TASKS_RCU */
  55. #ifdef CONFIG_SCHED_INFO
  56. struct sched_info sched_info;
  57. #endif
  58. //进程链表架构
  59. struct list_head tasks;
  60. #ifdef CONFIG_SMP
  61. struct plist_node pushable_tasks;
  62. struct rb_node pushable_dl_tasks;
  63. #endif
  64. // 进程管理地址空间,每个进程有独立的地址空间4G
  65. struct mm_struct *mm, *active_mm;
  66. /* per-thread vma caching */
  67. u32 vmacache_seqnum;
  68. struct vm_area_struct *vmacache[VMACACHE_SIZE];
  69. #if defined(SPLIT_RSS_COUNTING)
  70. struct task_rss_stat rss_stat;
  71. #endif
  72. // 进程状态参数
  73. /* task state */
  74. int exit_state;
  75. int exit_code, exit_signal;
  76. // 接收父进程终止时就会发出信号
  77. int pdeath_signal; /* The signal sent when the parent dies */
  78. unsigned long jobctl; /* JOBCTL_*, siglock protected */
  79. /* Used for emulating ABI behavior of previous Linux versions */
  80. unsigned int personality;
  81. /* scheduler bits, serialized by scheduler locks */
  82. unsigned sched_reset_on_fork:1;
  83. unsigned sched_contributes_to_load:1;
  84. unsigned sched_migrated:1;
  85. unsigned :0; /* force alignment to the next boundary */
  86. /* unserialized, strictly 'current' */
  87. unsigned in_execve:1; /* bit to tell LSMs we're in execve */
  88. unsigned in_iowait:1;
  89. #ifdef CONFIG_MEMCG
  90. unsigned memcg_may_oom:1;
  91. #endif
  92. #ifdef CONFIG_MEMCG_KMEM
  93. unsigned memcg_kmem_skip_account:1;
  94. #endif
  95. #ifdef CONFIG_COMPAT_BRK
  96. unsigned brk_randomized:1;
  97. #endif
  98. unsigned long atomic_flags; /* Flags needing atomic access. */
  99. struct restart_block restart_block;
  100. // 进程pid, 父进程tgid
  101. pid_t pid;
  102. pid_t tgid;
  103. // 防止内核堆栈溢出
  104. #ifdef CONFIG_CC_STACKPROTECTOR
  105. /* Canary value for the -fstack-protector gcc feature */
  106. unsigned long stack_canary;
  107. #endif
  108. /*
  109. * pointers to (original) parent process, youngest child, younger sibling,
  110. * older sibling, respectively. (p->father can be replaced with
  111. * p->real_parent->pid)
  112. */
  113. // 初始化父进程
  114. struct task_struct __rcu *real_parent; /* real parent process */
  115. // 接收中止进程
  116. struct task_struct __rcu *parent; /* recipient of SIGCHLD, wait4() reports */
  117. /*
  118. * children/sibling forms the list of my natural children
  119. */
  120. // 维护子进程链表
  121. struct list_head children; /* list of my children */
  122. // 兄弟进程链表
  123. struct list_head sibling; /* linkage in my parent's children list */
  124. struct task_struct *group_leader; /* threadgroup leader */
  125. /*
  126. * ptraced is the list of tasks this task is using ptrace on.
  127. * This includes both natural children and PTRACE_ATTACH targets.
  128. * p->ptrace_entry is p's link on the p->parent->ptraced list.
  129. */
  130. // 系统调用 关于断开调试
  131. struct list_head ptraced;
  132. struct list_head ptrace_entry;
  133. /* PID/PID hash table linkage. */
  134. // 散列表的关系
  135. struct pid_link pids[PIDTYPE_MAX];
  136. struct list_head thread_group;
  137. struct list_head thread_node;
  138. // do_fork()函数
  139. struct completion *vfork_done; /* for vfork() */
  140. int __user *set_child_tid; /* CLONE_CHILD_SETTID */
  141. int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
  142. // 描述CPU时间的内容
  143. // utime 用户态下的执行时间
  144. // stime 内核态的执行时间
  145. cputime_t utime, stime, utimescaled, stimescaled;
  146. cputime_t gtime;
  147. struct prev_cputime prev_cputime;
  148. #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
  149. seqlock_t vtime_seqlock;
  150. unsigned long long vtime_snap;
  151. enum {
  152. VTIME_SLEEPING = 0,
  153. VTIME_USER,
  154. VTIME_SYS,
  155. } vtime_snap_whence;
  156. #endif
  157. unsigned long nvcsw, nivcsw; /* context switch counts */
  158. u64 start_time; /* monotonic time in nsec */
  159. u64 real_start_time; /* boot based time in nsec */
  160. /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
  161. unsigned long min_flt, maj_flt;
  162. struct task_cputime cputime_expires;
  163. struct list_head cpu_timers[3];
  164. /* process credentials */
  165. const struct cred __rcu *real_cred; /* objective and real subjective task
  166. * credentials (COW) */
  167. const struct cred __rcu *cred; /* effective (overridable) subjective task
  168. * credentials (COW) */
  169. char comm[TASK_COMM_LEN]; /* executable name excluding path
  170. - access with [gs]et_task_comm (which lock
  171. it with task_lock())
  172. - initialized normally by setup_new_exec */
  173. /* file system info */
  174. struct nameidata *nameidata;
  175. #ifdef CONFIG_SYSVIPC
  176. /* ipc stuff */
  177. struct sysv_sem sysvsem;
  178. struct sysv_shm sysvshm;
  179. #endif
  180. #ifdef CONFIG_DETECT_HUNG_TASK
  181. /* hung task detection */
  182. unsigned long last_switch_count;
  183. #endif
  184. /* filesystem information */
  185. struct fs_struct *fs;
  186. /* open file information */
  187. struct files_struct *files;
  188. /* namespaces */
  189. struct nsproxy *nsproxy;
  190. /* signal handlers */
  191. struct signal_struct *signal;
  192. struct sighand_struct *sighand;
  193. sigset_t blocked, real_blocked;
  194. sigset_t saved_sigmask; /* restored if set_restore_sigmask() was used */
  195. struct sigpending pending;
  196. unsigned long sas_ss_sp;
  197. size_t sas_ss_size;
  198. struct callback_head *task_works;
  199. struct audit_context *audit_context;
  200. #ifdef CONFIG_AUDITSYSCALL
  201. kuid_t loginuid;
  202. unsigned int sessionid;
  203. #endif
  204. struct seccomp seccomp;
  205. /* Thread group tracking */
  206. u32 parent_exec_id;
  207. u32 self_exec_id;
  208. /* Protection of (de-)allocation: mm, files, fs, tty, keyrings, mems_allowed,
  209. * mempolicy */
  210. spinlock_t alloc_lock;
  211. /* Protection of the PI data structures: */
  212. raw_spinlock_t pi_lock;
  213. struct wake_q_node wake_q;
  214. #ifdef CONFIG_RT_MUTEXES
  215. /* PI waiters blocked on a rt_mutex held by this task */
  216. struct rb_root pi_waiters;
  217. struct rb_node *pi_waiters_leftmost;
  218. /* Deadlock detection and priority inheritance handling */
  219. struct rt_mutex_waiter *pi_blocked_on;
  220. #endif
  221. #ifdef CONFIG_DEBUG_MUTEXES
  222. /* mutex deadlock detection */
  223. struct mutex_waiter *blocked_on;
  224. #endif
  225. #ifdef CONFIG_TRACE_IRQFLAGS
  226. unsigned int irq_events;
  227. unsigned long hardirq_enable_ip;
  228. unsigned long hardirq_disable_ip;
  229. unsigned int hardirq_enable_event;
  230. unsigned int hardirq_disable_event;
  231. int hardirqs_enabled;
  232. int hardirq_context;
  233. unsigned long softirq_disable_ip;
  234. unsigned long softirq_enable_ip;
  235. unsigned int softirq_disable_event;
  236. unsigned int softirq_enable_event;
  237. int softirqs_enabled;
  238. int softirq_context;
  239. #endif
  240. #ifdef CONFIG_LOCKDEP
  241. # define MAX_LOCK_DEPTH 48UL
  242. u64 curr_chain_key;
  243. int lockdep_depth;
  244. unsigned int lockdep_recursion;
  245. struct held_lock held_locks[MAX_LOCK_DEPTH];
  246. gfp_t lockdep_reclaim_gfp;
  247. #endif
  248. /* journalling filesystem info */
  249. void *journal_info;
  250. /* stacked block device info */
  251. struct bio_list *bio_list;
  252. #ifdef CONFIG_BLOCK
  253. /* stack plugging */
  254. struct blk_plug *plug;
  255. #endif
  256. /* VM state */
  257. // 虚拟内存状态参数 内存回收
  258. struct reclaim_state *reclaim_state;
  259. // 存放块设备I/O流量信息
  260. struct backing_dev_info *backing_dev_info;
  261. // I/O调度器所用的信息
  262. struct io_context *io_context;
  263. unsigned long ptrace_message;
  264. siginfo_t *last_siginfo; /* For ptrace use. */
  265. struct task_io_accounting ioac;
  266. #if defined(CONFIG_TASK_XACCT)
  267. u64 acct_rss_mem1; /* accumulated rss usage */
  268. u64 acct_vm_mem1; /* accumulated virtual memory usage */
  269. cputime_t acct_timexpd; /* stime + utime since last update */
  270. #endif
  271. #ifdef CONFIG_CPUSETS
  272. nodemask_t mems_allowed; /* Protected by alloc_lock */
  273. seqcount_t mems_allowed_seq; /* Seqence no to catch updates */
  274. int cpuset_mem_spread_rotor;
  275. int cpuset_slab_spread_rotor;
  276. #endif
  277. #ifdef CONFIG_CGROUPS
  278. /* Control Group info protected by css_set_lock */
  279. struct css_set __rcu *cgroups;
  280. /* cg_list protected by css_set_lock and tsk->alloc_lock */
  281. struct list_head cg_list;
  282. #endif
  283. #ifdef CONFIG_FUTEX
  284. struct robust_list_head __user *robust_list;
  285. #ifdef CONFIG_COMPAT
  286. struct compat_robust_list_head __user *compat_robust_list;
  287. #endif
  288. struct list_head pi_state_list;
  289. struct futex_pi_state *pi_state_cache;
  290. #endif
  291. // 内存检测工具
  292. #ifdef CONFIG_PERF_EVENTS
  293. struct perf_event_context *perf_event_ctxp[perf_nr_task_contexts];
  294. struct mutex perf_event_mutex;
  295. struct list_head perf_event_list;
  296. #endif
  297. #ifdef CONFIG_DEBUG_PREEMPT
  298. unsigned long preempt_disable_ip;
  299. #endif
  300. #ifdef CONFIG_NUMA
  301. struct mempolicy *mempolicy; /* Protected by alloc_lock */
  302. short il_next;
  303. short pref_node_fork;
  304. #endif
  305. #ifdef CONFIG_NUMA_BALANCING
  306. int numa_scan_seq;
  307. unsigned int numa_scan_period;
  308. unsigned int numa_scan_period_max;
  309. int numa_preferred_nid;
  310. unsigned long numa_migrate_retry;
  311. u64 node_stamp; /* migration stamp */
  312. u64 last_task_numa_placement;
  313. u64 last_sum_exec_runtime;
  314. struct callback_head numa_work;
  315. struct list_head numa_entry;
  316. struct numa_group *numa_group;
  317. /*
  318. * numa_faults is an array split into four regions:
  319. * faults_memory, faults_cpu, faults_memory_buffer, faults_cpu_buffer
  320. * in this precise order.
  321. *
  322. * faults_memory: Exponential decaying average of faults on a per-node
  323. * basis. Scheduling placement decisions are made based on these
  324. * counts. The values remain static for the duration of a PTE scan.
  325. * faults_cpu: Track the nodes the process was running on when a NUMA
  326. * hinting fault was incurred.
  327. * faults_memory_buffer and faults_cpu_buffer: Record faults per node
  328. * during the current scan window. When the scan completes, the counts
  329. * in faults_memory and faults_cpu decay and these values are copied.
  330. */
  331. unsigned long *numa_faults;
  332. unsigned long total_numa_faults;
  333. /*
  334. * numa_faults_locality tracks if faults recorded during the last
  335. * scan window were remote/local or failed to migrate. The task scan
  336. * period is adapted based on the locality of the faults with different
  337. * weights depending on whether they were shared or private faults
  338. */
  339. unsigned long numa_faults_locality[3];
  340. unsigned long numa_pages_migrated;
  341. #endif /* CONFIG_NUMA_BALANCING */
  342. #ifdef CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH
  343. struct tlbflush_unmap_batch tlb_ubc;
  344. #endif
  345. struct rcu_head rcu;
  346. /*
  347. * cache last used pipe for splice
  348. */
  349. struct pipe_inode_info *splice_pipe; //管道
  350. struct page_frag task_frag;
  351. // 延迟计数
  352. #ifdef CONFIG_TASK_DELAY_ACCT
  353. struct task_delay_info *delays;
  354. #endif
  355. #ifdef CONFIG_FAULT_INJECTION
  356. int make_it_fail;
  357. #endif

进程优先级

  • 实时进程 非实时进程(普通进程)
    实时进程优先级(0-99)比普通进程的优先级高(100-139)高。当系统中有实时进程运行时,普通进程几乎无法分到时间片(只能分到5%的CPU时间)。

进程系统调用

进程复制

  1. fork是重量级调用,因为它建立了父进程的一个完整副本,然后作为子进程执行。 为减少与该调用相关的工作量,Linux使用了写时复制(copy-on-write)技术。
  2. vfork类似于fork,但并不创建父进程数据的副本。相反,父子进程之间共享数据。 这节省了大量CPU时间(如果一个进程操纵共享数据,则另一个会自动注意到)。
  3. clone产生线程,可以对父子进程之间的共享、复制进行精确控制

写时复制(Copy On Write)

内核使用了写时复制(Copy-On-Write,COW)技术,以防止在fork执行时将父进程的所有数据 复制到子进程。在调用fork时,内核通常对父进程的每个内存页,都为子进程创建一个相同的副本。

问题:主进程修改页z的数据,此时会发生父子进程在内存分离。

只有在不得不复制数据内容时采取复制数据内容,这就是写时复制的核心思想,可以看到因为修改页z导致子进程不得不去复制原来页z来保证父子进程互不干扰。
内核只为新生成的子进程创建虚拟空间结构,它们来复制父进程的虚拟结构,但是不为这些结构分配物理内存,它们共享父进程的物理空间,父进程有更改相应段的行为发生时,再为子进程相应段分配物理空间。

内核线程

内核线程是直接由内核本身启动的进程。内核线程实际上是将内核函数委托给独立的 进程,与系统中其他进程“并行”执行(实际上,也并不等于内核自身的执行)。内核线程经常 称之为(内核)守护进程。它们用于执行下列任务。

  • 周期性地将修改的内存页与页来源块设备同步(例如,使用mmap的文件映射)。
  • 如果内存页很少使用,则写入交换区。
  • 管理延时动作(deferred action)。
  • 实现文件系统的事务日志。

进程退出

进程必须用exit系统调用终止。这使得内核有机会将该进程使用的资源释放回系统。见kernel/exit.c------>do_exit。简而言之, 该函数的实现就是将各个引用计数器减1,如果引用计数器归0而没有进程再使用对应的结构,那么将相应的内存区域返还给内存管理模块

  1. void do_exit(long code)
  2. {
  3. struct task_struct *tsk = current;
  4. int group_dead;
  5. TASKS_RCU(int tasks_rcu_i);
  6. profile_task_exit(tsk);
  7. WARN_ON(blk_needs_flush_plug(tsk));
  8. if (unlikely(in_interrupt()))
  9. panic("Aiee, killing interrupt handler!");
  10. if (unlikely(!tsk->pid))
  11. panic("Attempted to kill the idle task!");
  12. /*
  13. * If do_exit is called because this processes oopsed, it's possible
  14. * that get_fs() was left as KERNEL_DS, so reset it to USER_DS before
  15. * continuing. Amongst other possible reasons, this is to prevent
  16. * mm_release()->clear_child_tid() from writing to a user-controlled
  17. * kernel address.
  18. */
  19. set_fs(USER_DS);
  20. ptrace_event(PTRACE_EVENT_EXIT, code);
  21. validate_creds_for_do_exit(tsk);
  22. /*
  23. * We're taking recursive faults here in do_exit. Safest is to just
  24. * leave this task alone and wait for reboot.
  25. */
  26. if (unlikely(tsk->flags & PF_EXITING)) {
  27. pr_alert("Fixing recursive fault but reboot is needed!\n");
  28. /*
  29. * We can do this unlocked here. The futex code uses
  30. * this flag just to verify whether the pi state
  31. * cleanup has been done or not. In the worst case it
  32. * loops once more. We pretend that the cleanup was
  33. * done as there is no way to return. Either the
  34. * OWNER_DIED bit is set by now or we push the blocked
  35. * task into the wait for ever nirwana as well.
  36. */
  37. tsk->flags |= PF_EXITPIDONE;
  38. set_current_state(TASK_UNINTERRUPTIBLE);
  39. schedule();
  40. }
  41. exit_signals(tsk); /* sets PF_EXITING */
  42. /*
  43. * tsk->flags are checked in the futex code to protect against
  44. * an exiting task cleaning up the robust pi futexes.
  45. */
  46. smp_mb();
  47. raw_spin_unlock_wait(&tsk->pi_lock);
  48. if (unlikely(in_atomic())) {
  49. pr_info("note: %s[%d] exited with preempt_count %d\n",
  50. current->comm, task_pid_nr(current),
  51. preempt_count());
  52. preempt_count_set(PREEMPT_ENABLED);
  53. }
  54. /* sync mm's RSS info before statistics gathering */
  55. if (tsk->mm)
  56. sync_mm_rss(tsk->mm);
  57. acct_update_integrals(tsk);
  58. group_dead = atomic_dec_and_test(&tsk->signal->live);
  59. if (group_dead) {
  60. hrtimer_cancel(&tsk->signal->real_timer);
  61. exit_itimers(tsk->signal);
  62. if (tsk->mm)
  63. setmax_mm_hiwater_rss(&tsk->signal->maxrss, tsk->mm);
  64. }
  65. acct_collect(code, group_dead);
  66. if (group_dead)
  67. tty_audit_exit();
  68. audit_free(tsk);
  69. tsk->exit_code = code;
  70. taskstats_exit(tsk, group_dead);
  71. exit_mm(tsk);
  72. if (group_dead)
  73. acct_process();
  74. trace_sched_process_exit(tsk);
  75. exit_sem(tsk);
  76. exit_shm(tsk);
  77. exit_files(tsk);
  78. exit_fs(tsk);
  79. if (group_dead)
  80. disassociate_ctty(1);
  81. exit_task_namespaces(tsk);
  82. exit_task_work(tsk);
  83. exit_thread();
  84. /*
  85. * Flush inherited counters to the parent - before the parent
  86. * gets woken up by child-exit notifications.
  87. *
  88. * because of cgroup mode, must be called before cgroup_exit()
  89. */
  90. perf_event_exit_task(tsk);
  91. cgroup_exit(tsk);
  92. /*
  93. * FIXME: do that only when needed, using sched_exit tracepoint
  94. */
  95. flush_ptrace_hw_breakpoint(tsk);
  96. TASKS_RCU(preempt_disable());
  97. TASKS_RCU(tasks_rcu_i = __srcu_read_lock(&tasks_rcu_exit_srcu));
  98. TASKS_RCU(preempt_enable());
  99. exit_notify(tsk, group_dead);
  100. proc_exit_connector(tsk);
  101. #ifdef CONFIG_NUMA
  102. task_lock(tsk);
  103. mpol_put(tsk->mempolicy);
  104. tsk->mempolicy = NULL;
  105. task_unlock(tsk);
  106. #endif
  107. #ifdef CONFIG_FUTEX
  108. if (unlikely(current->pi_state_cache))
  109. kfree(current->pi_state_cache);
  110. #endif
  111. /*
  112. * Make sure we are holding no locks:
  113. */
  114. debug_check_no_locks_held();
  115. /*
  116. * We can do this unlocked here. The futex code uses this flag
  117. * just to verify whether the pi state cleanup has been done
  118. * or not. In the worst case it loops once more.
  119. */
  120. tsk->flags |= PF_EXITPIDONE;
  121. if (tsk->io_context)
  122. exit_io_context(tsk);
  123. if (tsk->splice_pipe)
  124. free_pipe_info(tsk->splice_pipe);
  125. if (tsk->task_frag.page)
  126. put_page(tsk->task_frag.page);
  127. validate_creds_for_do_exit(tsk);
  128. check_stack_usage();
  129. preempt_disable();
  130. if (tsk->nr_dirtied)
  131. __this_cpu_add(dirty_throttle_leaks, tsk->nr_dirtied);
  132. exit_rcu();
  133. TASKS_RCU(__srcu_read_unlock(&tasks_rcu_exit_srcu, tasks_rcu_i));
  134. /*
  135. * The setting of TASK_RUNNING by try_to_wake_up() may be delayed
  136. * when the following two conditions become true.
  137. * - There is race condition of mmap_sem (It is acquired by
  138. * exit_mm()), and
  139. * - SMI occurs before setting TASK_RUNINNG.
  140. * (or hypervisor of virtual machine switches to other guest)
  141. * As a result, we may become TASK_RUNNING after becoming TASK_DEAD
  142. *
  143. * To avoid it, we have to wait for releasing tsk->pi_lock which
  144. * is held by try_to_wake_up()
  145. */
  146. smp_mb();
  147. raw_spin_unlock_wait(&tsk->pi_lock);
  148. /* causes final put_task_struct in finish_task_switch(). */
  149. tsk->state = TASK_DEAD;
  150. tsk->flags |= PF_NOFREEZE; /* tell freezer to ignore us */
  151. schedule();
  152. BUG();
  153. /* Avoid "noreturn function does return". */
  154. for (;;)
  155. cpu_relax(); /* For when BUG is null */
  156. }

总结

本文介绍了进程四要素、进程生命周期,列举了task_struct数据结构的主要内容,系统调用写时复制思想,守护进程,进程退出原理等内容。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/运维做开发/article/detail/764964
推荐阅读
相关标签
  

闽ICP备14008679号