Skip to content

Commit

Permalink
Create first process using kernel thread.
Browse files Browse the repository at this point in the history
  • Loading branch information
Godones committed Feb 19, 2024
1 parent 70ce42e commit ee550a0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion kernel/src/task/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub fn current_trap_frame() -> &'static mut TrapFrame {
pub fn do_exit(exit_code: i32) -> isize {
let task = current_task().unwrap();
let exit_code = (exit_code & 0xff) << 8;
if task.get_pid() == 0 {
if task.get_pid() == 1 {
println!("Init process exit with code {}", exit_code);
system_shutdown();
}
Expand Down
14 changes: 7 additions & 7 deletions kernel/src/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ pub static INIT_PROCESS: Lazy<Arc<Task>> = Lazy::new(|| {

/// 将初始进程加入进程池中进行调度
pub fn init_task() {
kthread::ktread_create(kthread_test, "kthread_test").unwrap();
let task = INIT_PROCESS.clone();
GLOBAL_TASK_MANAGER.add_task(Arc::new(FifoTask::new(task)));
println!("Init process success");
kthread::ktread_create(kthread_init, "kthread_test").unwrap();
println!("Init task success");
}

fn kthread_test() {
fn kthread_init() {
println!("kthread_init start...");
let task = INIT_PROCESS.clone();
GLOBAL_TASK_MANAGER.add_task(Arc::new(FifoTask::new(task)));
let mut time = get_time_ms();
println!("kthread_test start ...",);
loop {
let now = get_time_ms();
if now - time > 1000 {
// println!("kthread_test tick at {}", now);
// println!("kthread_init tick at {}", now);
time = now;
}
do_suspend();
Expand Down

0 comments on commit ee550a0

Please sign in to comment.