Source Code Project Nguyên Lý Hệ Điều Hành CT178 CT104

27 102 0
Source Code Project Nguyên Lý Hệ Điều Hành CT178 CT104

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

QUẢN LÝ BỘ NHỚ ĐỊNH THỜI CPU CT178 Nguyên Lý Hệ Điều Hành Truy cập https:www.ocit.cf TRƯỜNG ĐẠI HỌC CẦN THƠ KHOA CÔNG NGHỆ THÔNG TIN TRUYỀN THÔNG BÁO CÁO CODE PROJECT NGUYÊN LÝ HỆ ĐIỀU HÀNH HỌC KÌ I 2021 2022 Truy cập https:www.ocit.cf

TRƯỜNG ĐẠI HỌC CẦN THƠ KHOA CÔNG NGHỆ THÔNG TIN & TRUYỀN THÔNG BÁO CÁO CODE PROJECT NGUYÊN LÝ HỆ ĐIỀU HÀNH HỌC KÌ I 2021-2022 CT178-Nguyên Lý Hệ Điều Hành Truy cập https://www.ocit.cf/ Truy cập https://www.ocit.cf/ Để Xem Thêm CT178-Nguyên Lý Hệ Điều Hành Truy cập https://www.ocit.cf/ CT178-Nguyên Lý Hệ Điều Hành Truy cập https://www.ocit.cf/ PHẦN 1: XÂY DỰNG LINUX KERNEL Biên dịch Kernel Chỉnh sửa dòng CONFIG_SYSTEM_TRUSTED_KEYS=” debian/canonical-certs-pem” thành CONFIG_SYSTEM_TRUSTED_KEYS=”” #nano config Thay đổi file cấu hình GRUB Thay đổi file cấu hình grub: # nano /etc/default/grub Thực thay đổi sau: GRUB_DEFAULT=0 GRUB_TIMEOUT=25 CT178-Nguyên Lý Hệ Điều Hành Truy cập https://www.ocit.cf/ PHẦN 2: THÊM LỜI GỌI HỆ THỐNG VÀO LINUX KERNEL Viết chương trình hello.c #nano hello.c Nội dung: #include asmlinkage long sys_hello(void){ printk(“Xin chao, Toi la TRAN VAN THINH – B1906773 \n”); return 0; } Tạo tập tin Makefile #nano Makefile Obj-y := hello.o Chỉnh sửa tập tin Makefile Truy cập thư mục /root/linux-4.16.3/ sửa đổi tập tin Makefile #cd /root/linux4.16.3/ #nano Makefile Thêm “hello/” vào cuối dòng: core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ hello/ CT178-Nguyên Lý Hệ Điều Hành Truy cập https://www.ocit.cf/ Thêm lời gọi vào bảng gọi hệ thống Truy cập vào đường dẫn #cd /root/linux-4.16.3/arch/x86/entry/syscalls/ Sau Chỉnh sửa tập tin syscall_64.tbl #nano syscall_64.tbl Thêm dòng sau 548 64 hello sys_hello Thêm lời gọi hệ thống sys_hello() vào system call header file #cd /root/linux-4.16.3/include/linux #nano syscalls.h Thêm dòng “asmlinkage long sys_hello(void);” vào trước dòng #endif cuối CT178-Nguyên Lý Hệ Điều Hành Truy cập https://www.ocit.cf/ Thay đổi config #nano config Chỉnh sửa dòng CONFIG_SYSTEM_TRUSTED_KEYS=”” CT178-Nguyên Lý Hệ Điều Hành Truy cập https://www.ocit.cf/ Chỉnh sửa cấu hình GRUB #nano /etc/default/grub GRUB_DEFAULT=0 GRUB_TIMEOUT=25 Tạo lời gọi hệ thống #nano uesrspace.c #include #include #include #include int main(){ long int nmt = syscall(548); printf(“Loi goi he thong return %ld\n”,nmt); return 0; } CT178-Nguyên Lý Hệ Điều Hành Truy cập https://www.ocit.cf/ PHẦN 3: ĐỊNH THỜI CPU SOURCE CODE // TRAN VAN THNH // B1906773 #include #include #define Run #define Wait #define MAX 100 int q; int RR =1; typedef struct { int PID; int Arrive_Time; int Burst_Time; int Waiting_Time; int Turnaround_Time; int Response_Time; int Start_Time; int temp_Burst_Time; CT178-Nguyên Lý Hệ Điều Hành Truy cập https://www.ocit.cf/ int sum_Burst_Time; int Completion_Time; int State[500]; } Process; // ham tim max int Max(int a, int b) { if (a > b) return a; return b; } // ham sap xep theo Arrive Time void BubbleSort_Arrive(Process p[], int n) { int i, j; Process temp; for (i = 0; i < n; i++) { for (j = i + 1; j < n; j++) { if (p[i].Arrive_Time > p[j].Arrive_Time) { temp = p[i]; p[i] = p[j]; p[j] = temp; } } } return; 10 Truy cập https://www.ocit.cf/ p2[i].Waiting_Time = p2[i].Turnaround_Time - p2[i].Burst_Time; CT178-Nguyên Lý Hệ Điều Hành p2[i].Response_Time = p2[i].Start_Time - p2[i].Arrive_Time; } //Tao mang p3 de tra ve dung thu tu nhap cua Process for (i = 0; i < n; i++) for (j = 0; j < n; j++) if (i == p2[j].PID - 1) p3[i] = p2[j]; //tinh tong turnaround time, Waiting times, response time for (i = 0; i < n; i++) { sumTT += p3[i].Turnaround_Time; sumWT += p3[i].Waiting_Time; sumRT += p3[i].Response_Time; } // dat State = cho tat ca cac tien trinh for (i = 0; i < n; i++) for (j = 0; j < p2[n - 1].Completion_Time; j++) p3[i].State[j] = 0; // thiet lap State cho tat ca tien trinh for (i = 0; i < n; i++) for (j = 0; j < p2[n - 1].Completion_Time; j++) { if (p3[i].Start_Time = p3[i].Arrive_Time && j < p3[i].Start_Time) p3[i].State[j] = Wait; 13 CT178-Nguyên Lý Hệ Điều Hành Truy cập https://www.ocit.cf/ } // in output cua chuong trinh printf("\n"); printf("********************************\n"); printf("DINH THOI FCFS\n"); Output(p3, n, p2[n - 1].Completion_Time); printf("AVGW= %-2.2lf\t", (double) sumWT / (double) n); printf("AVGR= %-2.2lf \t", (double) sumWT / (double) n); printf("AVGT= %-2.2lf\t", (double) sumTT / (double) n); printf("\n"); } // ham dinh thoi SJF trung dung void SJF_TrungDung(Process p[], int n) { int sumWT = 0, sumTT = 0, sumRT = 0; int i, j, smallest, count = 0, time, end = 0, time2; int rtemp[n], rtemp2[n]; //Tao mang rtemp de nho thoi gian lan dau tien tien trinh duoc phan hoi //Tao mang rtemp de danh dau tien trinh nao da duoc phan hoi for (i = 0; i < n; i++) { rtemp[i] = 0; rtemp2[i] = 0; } // dat State = cho tat ca cac tien trinh for (i = 0; i < n; i++) 14 CT178-Nguyên Lý Hệ Điều Hành Truy cập https://www.ocit.cf/ for (j = 0; j < p[n].sum_Burst_Time; j++) p[i].State[j] = 0; //thiet lap gia tri cho temp burst time for (i = 0; i < n; i++) { p[i].temp_Burst_Time = p[i].Burst_Time; } //tinh Waiting time and turn around time p[9].temp_Burst_Time = 9999; for (time = 0; count != n; time++) { smallest = 9; for (i = 0; i < n; i++) if (p[i].Arrive_Time 0) smallest = i; p[smallest].temp_Burst_Time ; p[smallest].State[time] = Run; if (rtemp2[smallest] == 0) { rtemp[smallest] = time; rtemp2[smallest] = 1; } if (p[smallest].temp_Burst_Time == 0) { count++; end = time + 1; p[smallest].Waiting_Time = end - p[smallest].Arrive_Time - p[smallest].Burst_Time; p[smallest].Turnaround_Time = end - p[smallest].Arrive_Time; 15 CT178-Nguyên Lý Hệ Điều Hành Truy cập https://www.ocit.cf/ } time2 = time; } // thiet lap State cho tat ca cac tien trinh for (i = 0; i < n; i++) for (j = 0; j < time2; j++) if (j >= p[i].Arrive_Time && j < p[i].Turnaround_Time + p[i].Arrive_Time) if (p[i].State[j] != Run) p[i].State[j] = Wait; //tinh response time for (i = 0; i < n; i++) p[i].Response_Time = rtemp[i] - p[i].Arrive_Time; for (i = 0; i < n; i++) { sumWT += p[i].Waiting_Time; sumTT += p[i].Turnaround_Time; sumRT += p[i].Response_Time; } // in output cua chuong trinh printf("\n"); printf("********************************\n"); printf("DINH THOI SJF TRUNG DUNG\n"); Output(p, n, time2); printf("AVGW= %-2.2lf\t", (double) sumWT / (double) n); printf("AVGR= %-2.2lf \t", (double) sumRT / (double) n); printf("AVGT= %-2.2lf\t", (double) sumTT / (double) n); 16 CT178-Nguyên Lý Hệ Điều Hành Truy cập https://www.ocit.cf/ printf("\n"); } // ham dinh thoi SJF khong trung dung void SJF_khongTrungDung(Process p[], int n) { Process p2[n], p3[n]; int i, j, sumWT = 0, sumTT = 0, sumRT = 0; for (i = 0; i < n; i++) { p[n].sum_Burst_Time = p[i].Burst_Time; } for (i = 0; i < n; i++) { p2[i] = p[i]; } BubbleSort_Burst(p2, n); for (i = 0; i < n; i++) { if (i == 0) p2[i].Start_Time = p2[i].Arrive_Time; else p2[i].Start_Time = Max(p2[i - 1].Completion_Time, p2[i].Arrive_Time); p2[i].Completion_Time = p2[i].Start_Time + p2[i].Burst_Time; p2[i].Turnaround_Time = p2[i].Completion_Time - p2[i].Arrive_Time; p2[i].Waiting_Time = p2[i].Turnaround_Time - p2[i].Burst_Time; p2[i].Response_Time = p2[i].Start_Time - p2[i].Arrive_Time; } 17 CT178-Nguyên Lý Hệ Điều Hành Truy cập https://www.ocit.cf/ for (i = 0; i < n; i++) for (j = 0; j < n; j++) if (i == p2[j].PID - 1) p3[i] = p2[j]; //calculate sum turnaround time, Waiting times, response time for (i = 0; i < n; i++) { sumTT += p3[i].Turnaround_Time; sumWT += p3[i].Waiting_Time; sumRT += p3[i].Response_Time; } // set State = for all process for (i = 0; i < n; i++) for (j = 0; j < p2[n - 1].Completion_Time; j++) p3[i].State[j] = 0; // thiet lap State cho tat ca cac tien trinh for (i = 0; i < n; i++) for (j = 0; j < p2[n - 1].Completion_Time; j++) { if (p3[i].Start_Time = p3[i].Arrive_Time && j < p3[i].Start_Time) p3[i].State[j] = Wait; } // in output cua chuong trinh printf("\n"); printf("********************************\n"); 18 CT178-Nguyên Lý Hệ Điều Hành Truy cập https://www.ocit.cf/ printf("DINH THOI SJF KHONG TRUNG DUNG \n"); Output(p3, n, p2[n - 1].Completion_Time); printf("AVGW= %-2.2lf\t", (double) sumWT / (double) n); printf("AVGR= %-2.2lf \t", (double) sumWT / (double) n); printf("AVGT= %-2.2lf\t", (double) sumTT / (double) n); printf("\n"); } // ham dinh thoi Round Robin void Round_Robin(Process p[], int n, int q) { int i, j, pro, time, remain, flag = 0, k; int sumWT = 0, sumTT = 0, sum_Burst_Time = 0, sumRT = 0; remain = n; int rtemp[n], rtemp2[n]; if(RR == 0) { printf("\n"); printf("********************************\n"); printf("DINH THOI ROUND ROBIN \n "); printf("quantum =0 "); return 0; } //Tao mang rtemp de nho thoi gian lan dau tien tien trinh duoc phan hoi //Tao mang rtemp de danh dau tien trinh nao da duoc phan hoi for (i = 0; i < n; i++) { rtemp[i] = 0; rtemp2[i] = 0; } 19 CT178-Nguyên Lý Hệ Điều Hành Truy cập https://www.ocit.cf/ //Tinh tong burst time for (i = 0; i < n; i++) sum_Burst_Time += p[i].Burst_Time; // dat State = cho tat ca tien trinh for (i = 0; i < n; i++) for (j = 0; j < p[n].sum_Burst_Time; j++) p[i].State[j] = 0; for (i = 0; i < n; i++) { p[i].PID = i; p[i].temp_Burst_Time = p[i].Burst_Time; } BubbleSort_Arrive(p, n); for (time = 0, i = 0; remain != 0;) { if (p[i].temp_Burst_Time 0) { for (k = time; k < time + p[i].temp_Burst_Time; k++) p[i].State[k] = Run; if (rtemp2[i] == 0) { rtemp[i] = time; rtemp2[i] = 1; } time = time + p[i].temp_Burst_Time; p[i].temp_Burst_Time = 0; flag = 1; 20 CT178-Nguyên Lý Hệ Điều Hành Truy cập https://www.ocit.cf/ } else if (p[i].temp_Burst_Time > 0) { p[i].temp_Burst_Time = p[i].temp_Burst_Time - q; for (k = time; k < time + q; k++) p[i].State[k] = Run; if (rtemp2[i] == 0) { rtemp[i] = time; rtemp2[i] = 1; } time = time + q; } if (p[i].temp_Burst_Time == && flag == 1) { remain ; p[i].Turnaround_Time = time - p[i].Arrive_Time; p[i].Waiting_Time = time - p[i].Arrive_Time - p[i].Burst_Time; flag = 0; } if (i == n - 1) i = 0; else if (p[i + 1].Arrive_Time = p[i].Arrive_Time && j < p[i].Turnaround_Time + p[i].Arrive_Time) if (p[i].State[j] != Run) p[i].State[j] = Wait; // in output cua chuong trinh printf("\n"); printf("********************************\n"); printf("DINH THOI ROUND ROBIN \n "); Output(p, n, sum_Burst_Time); printf("AVGW= %-2.2lf\t", (double) sumWT / (double) n); printf("AVGR= %-2.2lf \t", (double) sumRT / (double) n); printf("AVGT= %-2.2lf\t", (double) sumTT / (double) n); printf("\n"); } int main() { Process p[MAX]; int i, j, n; int sumWT = 0, sumTT = 0; printf("Nhap so tong so tien trinh: "); scanf("%d", & n); 22 CT178-Nguyên Lý Hệ Điều Hành Truy cập https://www.ocit.cf/ if(n 0) { decNumber += (binaryNum % 10) * pow(2, p); ++p; binaryNum /= 10; } return decNumber; } 24 CT178-Nguyên Lý Hệ Điều Hành Truy cập https://www.ocit.cf/ long long Dec2Bin(int decimalNum) { long long binaryNum = 0; int p = 0; while (decimalNum > 0) { binaryNum += (decimalNum % 2) * pow(10, p); ++p; decimalNum /= 2; } return binaryNum; } int QuanLy(int n, int pagesize) { int p = n / pagesize; int d = n % pagesize; int khung = 0; long long realBin = 0; int phyA = 0; switch (p) { case 0: khung = 6; break; case 1: khung = 5; break; case 2: khung = 4; break; case 3: khung = 2; break; case 4: khung = 7; 25 CT178-Nguyên Lý Hệ Điều Hành Truy cập https://www.ocit.cf/ break; case 5: khung = 3; break; case 6: khung = 1; break; default: khung = -1; break; } //128 bytes = 2^7 realBin = BinToDec(khung) * pow(10, 7) + Dec2Bin(d); phyA = BinToDec(realBin); if (khung == -1) return -1; return phyA; } int main() { //128 la page size int decimalNum, n, i, Data, temp; freopen("data.txt", "r", stdin); scanf("%d", & n); for (i = 0; i < n; i++) { scanf("%d", & Data); temp = QuanLy(Data, 128); if (temp == -1) printf("Khong tim thay dia chi vat ly cua %d!\n", Data); else printf("dia chi vat ly cua %d la: %d\n", Data, QuanLy(Data, 128)); } } KẾT QUẢ 26 CT178-Nguyên Lý Hệ Điều Hành Truy cập https://www.ocit.cf/ 27 .. .CT178 -Nguyên Lý Hệ Điều Hành Truy cập https://www.ocit.cf/ Truy cập https://www.ocit.cf/ Để Xem Thêm CT178 -Nguyên Lý Hệ Điều Hành Truy cập https://www.ocit.cf/ CT178 -Nguyên Lý Hệ Điều Hành. .. #endif cuối CT178 -Nguyên Lý Hệ Điều Hành Truy cập https://www.ocit.cf/ Thay đổi config #nano config Chỉnh sửa dòng CONFIG_SYSTEM_TRUSTED_KEYS=”” CT178 -Nguyên Lý Hệ Điều Hành Truy cập https://www.ocit.cf/... SJF_TrungDung(p, n); Round_Robin(p, n, q); return 0; 23 CT178 -Nguyên Lý Hệ Điều Hành Truy cập https://www.ocit.cf/ } KẾT QUẢ PHẦN 4: QUẢN LÝ BỘ NHỚ SOURCE CODE #include #include int

Ngày đăng: 28/09/2022, 23:57

Hình ảnh liên quan

2. Thay đổi file cấu hình GRUB - Source Code Project Nguyên Lý Hệ Điều Hành CT178 CT104

2..

Thay đổi file cấu hình GRUB Xem tại trang 4 của tài liệu.
4. Thêm lời gọi mới vào bảng gọi hệ thống - Source Code Project Nguyên Lý Hệ Điều Hành CT178 CT104

4..

Thêm lời gọi mới vào bảng gọi hệ thống Xem tại trang 6 của tài liệu.
7. Chỉnh sửa cấu hình GRUB - Source Code Project Nguyên Lý Hệ Điều Hành CT178 CT104

7..

Chỉnh sửa cấu hình GRUB Xem tại trang 8 của tài liệu.

Tài liệu cùng người dùng

Tài liệu liên quan