+__DEFINE_LXSYSCALL1(unsigned int, alarm, unsigned int, seconds)
+{
+ time_t prev_ddl = __current->sleep.alarm_time;
+ time_t now = clock_systime();
+
+ __current->sleep.alarm_time = seconds ? now + seconds * 1000 : 0;
+
+ if (llist_empty(&__current->sleep.sleepers)) {
+ llist_append(&sched_ctx._procs[0].sleep.sleepers,
+ &__current->sleep.sleepers);
+ }
+
+ return prev_ddl ? (prev_ddl - now) / 1000 : 0;
+}
+
+__DEFINE_LXSYSCALL1(void, exit, int, status)
+{
+ terminate_proc(status);
+ schedule();
+}
+
+__DEFINE_LXSYSCALL(void, yield)
+{
+ schedule();
+}
+
+pid_t
+_wait(pid_t wpid, int* status, int options);
+
+__DEFINE_LXSYSCALL1(pid_t, wait, int*, status)
+{
+ return _wait(-1, status, 0);
+}
+
+__DEFINE_LXSYSCALL3(pid_t, waitpid, pid_t, pid, int*, status, int, options)
+{
+ return _wait(pid, status, options);
+}
+
+__DEFINE_LXSYSCALL(int, geterrno)
+{
+ return __current->k_status;
+}
+
+pid_t
+_wait(pid_t wpid, int* status, int options)
+{
+ pid_t cur = __current->pid;
+ int status_flags = 0;
+ struct proc_info *proc, *n;
+ if (llist_empty(&__current->children)) {
+ return -1;
+ }
+
+ wpid = wpid ? wpid : -__current->pgid;
+ cpu_enable_interrupt();
+repeat:
+ llist_for_each(proc, n, &__current->children, siblings)
+ {
+ if (!~wpid || proc->pid == wpid || proc->pgid == -wpid) {
+ if (proc->state == PS_TERMNAT && !options) {
+ status_flags |= PEXITTERM;
+ goto done;
+ }
+ if (proc->state == PS_STOPPED && (options & WUNTRACED)) {
+ status_flags |= PEXITSTOP;
+ goto done;
+ }
+ }
+ }
+ if ((options & WNOHANG)) {
+ return 0;
+ }
+ // 放弃当前的运行机会
+ sched_yield();
+ goto repeat;
+
+done:
+ cpu_disable_interrupt();
+ status_flags |= PEXITSIG * (proc->sig_inprogress != 0);
+ if (status) {
+ *status = proc->exit_code | status_flags;
+ }
+ return destroy_process(proc->pid);
+}
+
+struct proc_info*
+alloc_process()
+{