目錄
一、設計目的與要求
二、設計內容
三、設備與環境
四、設計思想
五、主要資料結構與流程
六、實驗測試結果及結果剖析
七、課程設計總結
附件1課程設計答辯紀錄
附件2來源程式清單
一、設計目的與要求
該課設的設計目的是讓中學生了解Linux系統呼叫的實作原理,掌握Linux核心原始碼的變更方式,以及把握怎麼編撰呼叫程式來呼叫新增的系統呼叫。要求中學生就能獨立完成該課設,並且才能理解系統呼叫的概念和實作方式。
二、設計內容
採用編譯內核法作業系統原理與linux系統實驗,重新編譯Linux內核,在Linux中降低一個系統呼叫。
要求:(1)系統呼叫實現的功能:估算一個數字的三次方,並複印下來。 (2)另外寫一個程式進行呼叫。
三、設備與環境
設備:VMwareWorkstationPro
環境:Ubantu15.0.2
映像:ubuntu-16.04-desktop-amd64.iso
四、設計思想4.1設計思路
更改Linux內核,降低一個新的系統呼叫來實現估算一個數字的三次方並複印下來的功能,包括下載Linux內核原始碼,並進行更改編譯更改後的Linux內核,並將其安裝到系統中,編撰一個呼叫這個新系統呼叫的程式。
4.2主要步驟
(1)查看原先內核:
(2)下載新核心:
wget作業系統原理與linux系統實驗linux移植,之後回車。結果如圖
(3) Connect the downloaded installation package to the /usr/src directory, and then unzip it. Enter the following command in the terminal, and the result is as shown
mvlinux-5.6.15.tar.gz/usr/src
cd/usr/src
tar-xvflinux-5.6.15.tar.gz
(4) Download the super editor vim (already downloaded before). I have already downloaded it here. If it is not downloaded, you can use sudoapt-get-yinstallvim to download it
(5) New system call:
Add calling function declaration: viminclude/linux/syscalls.h
Add asmlinkagelongsys_cube(intnum);
before #ifndefNote: i enters the editing mode, after adding, Esc returns to linux transplantation, and finally shift+: hit wq to save and exit.
(6) Add the calling function definition, enter vimkernel/sys.c, and add the function at the end of the article
SYSCALL_DEFINE1(cube,int,num){
intresult=numnumnum;
printk(“Theresultis%d.n”,result);
returnresult;
(7)Add system call number
Enter vimarch/x86/entry/syscalls/syscall_64.tbl and add 439 items in the syscall_64.tbl file
(8) Install the dependency packages required to compile the kernel:
apt-get -y install make apt-get -y install libncurses5-dev apt-get -y install flex apt-get -y install bison apt-get -y install libssl-dev apt-get -y install libelf-dev
(9) Configure the kernel
Enter makemenuconfig and execute [Save]->[Ok]->[Exit]->[Exit] in the pop-up interface
(10)Compile
Type make-j8 in [Terminal] (8 threads start compilation), it will take about an hour, and the compilation is completed as shown in the picture
Type the makemodules and makemodules_install commands to complete the compilation and installation of the module respectively.
(11)Install kernel
【Terminal】Input makeinstall
(12)Restart the system
[Terminal] Enter uname-r to check the kernel version. As shown in the picture, the kernel has been recompiled
Compile calling program:
Exit after saving, and execute gcctest.c-otest.out and ./test.out in [Terminal] to get the test results
5. Main data structures and processes
以上是深入探究 Linux 系統調用:新增計算數字三次方並列印的系統調用的詳細內容。更多資訊請關注PHP中文網其他相關文章!