
Linux内核之进程管理
文章平均质量分 75
SunnyBeiKe
喜爱计算机,励志考研深造!
展开
-
进程管理之schedule()
/* * schedule() is the main scheduler function. */asmlinkage void __sched schedule(void){ struct task_struct *prev, *next; unsigned long *switch_count; struct rq *rq; int cpu;need_resched:原创 2011-10-28 18:03:34 · 3480 阅读 · 0 评论 -
进程管理之CFS调度器
/* * All the scheduling class methods: */static const struct sched_class fair_sched_class = { .next = &idle_sched_class, //指向下一个调度器 .enqueue_task = enqueue_task_fair, .dequeue_task = dequeu原创 2011-11-08 17:08:48 · 4661 阅读 · 0 评论 -
进程管理之RT调度器
想比于前面文章讲到的CFS的调度器,RT调度器就简单许多,RT的调度算法也相应的简单很多。static const struct sched_class rt_sched_class = { .next = &fair_sched_class, .enqueue_task = enqueue_task_rt, .dequeue_task = dequeue_task_rt,原创 2011-11-08 21:50:24 · 5012 阅读 · 1 评论 -
进程管理之schedule->context_switch()
在挑选得到了下一个即将被调度进来的进程之后,如果被选中的进程不是当前正在运行的进程,那么需要进行上下文切换以执行被选中的进程: context_switch(rq, prev, next); /* unlocks the rq */ /* * The context switch have flipped the stack from und原创 2011-11-07 22:40:46 · 3810 阅读 · 0 评论 -
调度时机
我们知道了进程是如何被调度了,但是进程什么时候会被调度呢?在什么情况下被调度呢?调度只有当CPU在内核中运行时才有可能发生。有两种情况:(1)“自愿”的,通过像sleep()之类的系统调用实现;或者实在通过其他系统调用进入内核以后因某种原因受阻需要等待,而自愿让内核调度其他进程执行。(2)“强制”的,当一个进程连续运行的时间超过一定的限度时,内核就会强制地调度其他进程来执行。《情景分析》P23原创 2011-11-08 11:12:49 · 1226 阅读 · 0 评论 -
进程管理之yield()
/** * yield - yield the current processor to other threads. * * This is a shortcut for kernel-space yielding - it marks the * thread runnable and calls sys_sched_yield(). */void __sched yield(vo原创 2011-11-08 11:06:30 · 6593 阅读 · 0 评论 -
进程管理之schedule --> pick_next_task()
/* * Pick up the highest-prio task: */static inline struct task_struct *pick_next_task(struct rq *rq){ const struct sched_class *class; struct task_struct *p; /* * Optimization: we know tha原创 2011-10-30 13:16:14 · 5362 阅读 · 1 评论 -
进程创建之do_fork
/* * Ok, this is the main fork-routine. * * It copies the process, and if successful kick-starts * it and waits for it to finish using the VM if required. */long do_fork(unsigned long clone_fla原创 2011-10-18 21:39:33 · 2438 阅读 · 0 评论 -
do_fork->copy_process->copy_mm
static int copy_mm(unsigned long clone_flags, struct task_struct * tsk){ struct mm_struct * mm, *oldmm; int retval; tsk->min_flt = tsk->maj_flt = 0; tsk->nvcsw = tsk->nivcsw = 0;#ifdef CONFIG_D原创 2011-10-23 15:44:06 · 3452 阅读 · 0 评论 -
系统调用execve的入口sys_execve()
/* * sys_execve() executes a new program. */long sys_execve(const char __user *name, //需要执行的文件的绝对路径(存于用户空间) const char __user *const __user *argv, //传入系统调用的参数(存于用户空间) const ch原创 2011-10-24 22:47:17 · 9935 阅读 · 0 评论 -
进程(组)/线程(组)/会话
可以参看UNIX环境高级编程的相关章节。为了搞清楚进程组之间的关系,我们做如下的实验:编写程序:/*test.c*/#include "../include/apue.h"void main() { pid_t pid; char *args[] = {"/bin/echo", "Hello", "World!", NULL }; if((pid = fork()原创 2011-10-26 16:55:03 · 2542 阅读 · 0 评论 -
do_exit——>exit_notify()
/* * Send signals to all our closest relatives so that they know * to properly mourn(悼念) us.. */static void exit_notify(struct task_struct *tsk, int group_dead){ int signal; void *cookie; /*原创 2011-10-26 19:28:28 · 4326 阅读 · 0 评论 -
Linux3.0.6内核task_struct注释
struct task_struct { volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */ void *stack; //stack should points to a threadinfo struct atomic_t usage; //有几个进程正在使用该结构 unsigned int flags; /原创 2011-10-13 14:34:52 · 8316 阅读 · 0 评论 -
内核进程创建之分配task_struct(do_fork->copy_process->dup_task_struct())
static struct task_struct *dup_task_struct(struct task_struct *orig){ struct task_struct *tsk; //sizeof(task_struct) = 3236;这个值是通过gdb得到的, //可以看到单个的task_struct原创 2011-10-17 21:18:00 · 4024 阅读 · 0 评论 -
进程创建之dofork->copy_process()
/* * This creates a new process as a copy of the old one, * but does not actually start it yet. * * It copies the registers, and all the appropriate * parts of the process environment (as per the原创 2011-10-17 23:46:47 · 2632 阅读 · 0 评论 -
进程管理之exit()
NORET_TYPE void do_exit(long code){ struct task_struct *tsk = current; int group_dead; profile_task_exit(tsk); WARN_ON(atomic_read(&tsk->fs_excl)); //如果进程holding fs exclusive resources,则报错。但是还原创 2011-10-25 22:12:37 · 4074 阅读 · 0 评论