+int
+can_schedule(struct proc_info* proc)
+{
+ if (__SIGTEST(proc->sig_pending, _SIGCONT)) {
+ __SIGCLEAR(proc->sig_pending, _SIGSTOP);
+ } else if (__SIGTEST(proc->sig_pending, _SIGSTOP)) {
+ // 如果进程受到SIGSTOP,则该进程不给予调度。
+ return 0;
+ }
+
+ return 1;
+}
+
+void
+check_sleepers()
+{
+ struct proc_info* leader = &sched_ctx._procs[0];
+ struct proc_info *pos, *n;
+ time_t now = clock_systime();
+ llist_for_each(pos, n, &leader->sleep.sleepers, sleep.sleepers)
+ {
+ if (PROC_TERMINATED(pos->state)) {
+ goto del;
+ }
+
+ time_t wtime = pos->sleep.wakeup_time;
+ time_t atime = pos->sleep.alarm_time;
+
+ if (wtime && now >= wtime) {
+ pos->sleep.wakeup_time = 0;
+ pos->state = PS_STOPPED;
+ }
+
+ if (atime && now >= atime) {
+ pos->sleep.alarm_time = 0;
+ __SIGSET(pos->sig_pending, _SIGALRM);
+ }
+
+ if (!wtime && !atime) {
+ del:
+ llist_delete(&pos->sleep.sleepers);
+ }
+ }
+}
+
+void
+schedule()
+{