【问题标题】:What is set_current_state() macro in kernel thread?内核线程中的 set_current_state() 宏是什么?
【发布时间】:2015-05-21 19:40:47
【问题描述】:
在学习内核线程时,我遇到了这段代码
while(!kthread_should_stop()){
set_current_state(TASK_RUNNING);
/* Doing some stuff here */
set_current_state(TASK_INTERRUPTIBLE);
msleep(1000);
宏set_current_state是做什么用的,传递的参数是什么。
【问题讨论】:
标签:
c
linux
linux-kernel
linux-device-driver
【解决方案1】:
根据这篇LinuxJournal 文章
set_current_state() 将当前执行进程的状态从TASK_RUNNING 更改为TASK_INTERRUPTIBLE。
这里,TASK_RUNNING 和 TASK_INTERRUPTIBLE 是进程的两个状态。
-
TASK_RUNNING -- 准备运行的进程的状态为 TASK_RUNNING。
-
TASK_INTERRUPTIBLE -- 进程的状态,即schedule() 被调用,进程从运行队列中移出。