乙個簡單的時間片輪轉多道程式核心作業系統工作流程

2021-06-29 03:37:39 字數 1897 閱讀 4986

一.作業系統工作概述

儲存程式計算機工作模型,計算機系統最最基礎性的邏輯結構;

函式呼叫堆疊,高階語言得以執行的基礎;

中斷,多道程式作業系統的基點。

二.**分析

主要對mypcb.h,  mymain.c 和myinterrupt.c這三個檔案進行分析。

#define max_task_num        4

#define kernel_stack_size 1024*8

/* cpu-specific state of this task */

struct thread ;

typedef struct pcbtpcb;

#include #include #include #include #include #include "mypcb.h"    //引入其中兩個結構體表示

tpcb task[max_task_num];//定義兩個陣列

tpcb * my_current_task = null;

volatile int my_need_sched = 0;//定義是否排程, 1則排程, 0則不排程

void my_process(void);

void __init my_start_kernel(void) //起始函式位置

printk(kern_notice "this is process %d +\n",my_current_task->pid);

} }}

#include #include #include #include #include #include "mypcb.h"

extern tpcb task[max_task_num];

extern tpcb * my_current_task;

extern volatile int my_need_sched;

volatile int time_count = 0;

/* * called by timer interrupt.

* it runs in the name of current running process,

* so it use kernel stack of current running process

*/void my_timer_handler(void)

time_count ++ ;

#endif

return;

}void my_schedule(void) //排程函式, 核心函式

printk(kern_notice ">>>my_schedule

next = my_current_task->next;//把當前程序的下乙個程序賦值給next,當前程序賦值給prev

prev = my_current_task;

if(next->state == 0)/* -1 unrunnable, 0 runnable, >0 stopped */

else

return;

}

借用另一篇博文,以新任務切換為例進行堆疊變化分析:

author: 于凱

參考課程:《linux核心分析》mooc課程

乙個簡單的時間片輪轉多道程式分析

使用實驗樓的虛擬機器開啟shell 輸入下面的兩條命令,即可以啟動 mykernel,l cd linuxkernel linux 3.9.4 l qemu kernel arch x86 boot bzimage 下圖為執行截圖 這個程式很簡單,程式在兩個函式之間按時間進行切換。函式中沒有其它功能...

乙個簡單的時間獲取程式

客戶程式 include unp.h include myerror.h int main int argc,char argv 建立乙個tcp套接字,返回sockfd作為套接字描述符 int sockfd if sockfd socket af inet,sock stream,0 0 指定伺服器...

乙個簡單的時間獲取客戶程式

讓我們考慮乙個具體例子,引入將本書中遇到的許多概念和說法。實現乙個tcp當前時間查詢客戶程式的實現。該客戶程式與其伺服器建立乙個tcp連線後,伺服器直觀可讀格式簡單地送回當前時間和日期。獲取時間的伺服器端 include include include include include include...