Fork me on GitHub

Operating System Concepts Reading Report

ABSTRACT

After reading operating system concepts,I have a glimpse of the Principles of the operating system. There are ten parts in this book, including process management, memory management, storage Management, file system, security and so on. In this essay, I will introduce what is the operating system and how it implements process management, why is Java so popular, the dining-philosophers problem,memory management and comparison of different operating systems.

What is operating system?

The operating system is a computer program that manages the hardware and software resources of a computer, and it is also the kernel and cornerstone of a computer system. The operating system needs to deal with such basic affairs as managing and configuring memory, deciding the priority of system resource supply and demand, controlling input device and output device, operating network and managing file system. The operating system also provides an operating interface for users to interact with the system.

How it implements process management?

The process is a stand-alone, concurrently executing program runs on a data set, as a separate unit of the system for resource allocation and scheduling. There are plenty of characteristics of the process, such as dynamicity,concurrency, independence, asynchrony and structural features. These characteristics determine that it is very important for the operating system to have good process management. As long as, there are three basic states of a process:Ready state (get all resources except the processor), Execution state (gets processor, is executing), Blocking state (the state in which execution is suspended due to an event).

在这里插入图片描述
Figure 1. Process change chart. Execution-Ready: out of allocated time. Execution-Wait: a process is blocked and stopped due to I / O request and buffer space application. Blocking - Ready: I / O request, end of application buffer space, enter ready queue.

Process scheduling algorithm is very important for an operating system to manage processes reasonably.
The following is the common process scheduling algorithm:

Fifo algorithm:
First come, first served processor to the process that enters the ready queue first.

Priority scheduling algorithm for the shortest processor running time:
Turnaround time = completion time - starting time (submission time)
Turnaround time with rights = turnaround time/running time (service time required)
It can only be predicted based on the execution history of each process.

The highest response ratio priority scheduling algorithm:
Response ratio = (wait time + required service time)/ required service time
Short processes are advantageous and can be implemented as a priority.
Once the process has acquired the processor, it will execute until the process ends or voluntarily gives up the processor for waiting for an event.

Priority scheduling algorithm:
Static: determined at the time the process was created, based on the type of process, the need for resources, and the priority of the user.
Dynamic: adjusts dynamically with execution time.

Time slice scheduling algorithm:
An appropriate clock constant is added to the fifo principle to interrupt.

Foreground and background scheduling algorithm:
The foreground program is executed according to the time slice scheduling algorithm.
Background processes typically run on a first come, first served basis.

Multi-stage feedback queue rotation algorithm:
Set up different levels of ready queues to schedule.
The next higher priority queue is scheduled only if the team is empty.

The Java language first introduced the slogan "Write Once, Run Anywhere". In this book, I finally know the reason. The Java virtual machine has its own perfect hardware architecture, such as processor, stack, register, and so on, as well as the corresponding instruction system. The Java virtual machine (JVM) shields information about specific operating system platforms, allowing Java programs to run unchanged on multiple platforms simply by generating the bytecode that runs on the JVM.When the virtual machine runs a program, it uses the classloader to load the class file of the Java program, and applies a memory area as the running data area in the computer. It is used to store class files of programs, static objects and instance objects created, methods, local variables, intermediate results, return values of methods, etc. In order to manage and effectively use the applied memory area, the virtual machine divides the memory into heap, stack, method area, program counter and local method stack. Thread private, life cycle and thread. Describes the memory model of Java method execution: each method creates a Stack Frame at execution time to store local variables, operand stacks, dynamic links, method exits, and so on. Each method from call to execution corresponds to a stack frame being pushed from the virtual machine stack to the stack.Now let's use a diagram to show the contents of each area storage.

在这里插入图片描述Figure 2. The contents of each area storage. Data area shared by all threads and thread isolated data area.

The Dining-Philosophers Problem

The dinning philosophers problem is one of the classic synchronization problems. Philosopher's meal problem is a typical example of a large class of concurrent control problems, involving the application of semaphore mechanism, management mechanism, deadlock and other key problems in the operating system. The analysis of this problem is helpful to understand the resource sharing, process synchronization and deadlock in computer system.
在这里插入图片描述

Figure 3. The Dining-Philosophers Problem

In order to solve the deadlock problem, the philosopher is allowed to pick up the chopsticks and eat only when both chopsticks are available. It can be realized by and semaphore mechanism, or by semaphore protection mechanism. The idea of using semaphore protection mechanism is to protect the operation of taking left and right chopsticks by recording semaphore mutex, making it an atomic operation, which can prevent deadlock.

The description is as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
semaphore mutex = 1; 
semaphore chopstick[5]={1,1,1,1,1};
void philosopher(int i)
{
while(true)
{
think();
wait(mutex);
wait(chopstick[(i+1)%5]);
wait(chopstick[i]);
signal(mutex);
eat();
signal(chopstick[(i+1)%5]);
signal(chopstick[i]);
}
}

Memory Management

Because the current operating system supports multithreading, multithreading does not need to run these processes at the same time. As long as they are in the ready state, the operating system can quickly switch between them, and achieve the illusion of simultaneous operation. Each process needs memory. When context switch is used, what about the contents in memory? The simple and crude way is to dump to the disk first, and then restore the contents of the dump (if any) from the disk, but the effect is too slow. Then how can it be faster? Leave the memory corresponding to the process in the physical memory, and switch to a specific area when necessary. This involves the protection mechanism of memory. After all, the content that can be read or written between processes is disorderly and unsafe. Therefore, the operating system needs to make a layer of abstraction for physical memory, that is, address space. The address space of a process contains all the relevant memory of the process, such as code, stack and heap.

Paging is very important in memory management.Paging's idea is to divide the address space into fixed size units. For example, the following address space is only 64 bytes, 16 bytes per page. As you can see, although the address space is continuous, the physical address is not. The advantage of this is that you don't need to consider how many sizes heap / stack will be applied for. Given an example that, to apply for 64 byte address space, you only need to give four free pages, so the OS management is very simple. For instance, you only need to maintain a list of free pages, and then give the first four. In order to record the relationship between virtual page and physical address, the OS needs to maintain a page table for each process. Its function is address translation.

Comparison of different operating systems

In order to apply different scenarios, various operating systems are derived. At present, the most common operating systems are PC operating system, mobile operating system and real-time operating system.Among them, the mobile operating system has a high demand for endurance, so the mobile operating system is strict with the background process management, often shutting down the process that has not been used for a long time. The operating system of PC can't shut down the background process, which is determined by different scenarios, while real-time operating system is mostly used in embedded system. For example, in the control system of automobile, it is very dangerous to execute the brake command a few millimeters later. Real time operating system refers to an operating system that can accept and process external events or data at a fast enough speed when they are generated, and the result of its processing can control the production process or respond to the processing system quickly within a specified time, schedule all available resources to complete real-time tasks, and control all real-time tasks to run in a coordinated manner. Providing timely response and high reliability are its main characteristics.

数字杭电分析

最近一段时间突发其想打算做个类似携程抢火车票一样的云抢课平台,项目做了一大半突然看见新闻有人做帮其他人抢火车票的生意被逮起来的。而且云抢课平台一旦做起来,学校的土豆服务器肯定分分钟崩溃,到时候学校肯定要请我去喝茶。所以把我这段时间的研究成果公开供大家学习。文中有什么不对的地方还请各位大佬指出。

首先,学校的抢课系统是比较常见的正方教务系统,按理来说应该非常简单。但是,对比其他正方教务系统,显然我们学校的教务系统登录页面被关闭,而采用了CAS,Central Authentication Service—中央认证服务。

在这里插入图片描述

但是,对比其他正方教务系统,显然我们学校的教务系统登录页面被关闭,而采用了CAS,Central Authentication Service—中央认证服务。
在这里插入图片描述

在github上找到一位杭电16级学长做过的类似的项目,但是学校的登录系统又进行了升级,后来要到了学长的联系方式,通过交流我也大概了解到思路,于是开始研究新版数字杭电登录系统。

首先用chrome进行抓包
在这里插入图片描述

可以看到登录的数据进行了rsa非对称加密算法进行了加密,老版的数字杭电登录系统采用的是md5加密算法。

知道采用rsa加密后首先想到去前端的js里面查找加密函数
在这里插入图片描述

果然找到了一个名称为des的js文件,刚好鄙人上学期选修了信息安全技术的专业选修课,课上研究过des+rsa的加密。打开des.js果然就是页面所采取的加密算法。

下一步在login.js的代码里面找到调用加密函数的语句
在这里插入图片描述

经过分析u就是学号,p是密码,lt是loginticket

紧接着就是获取loginticket,经过学长的指导,得知loginticket在html中。
在这里插入图片描述

此时我们在代码中通过正则表达式则可以把lt提取出来
在这里插入图片描述
在这里插入图片描述
此时rsa加密部分基本上已经分析完毕了

紧接着将des.js保存,并通过python的execjs库调用加密函数
在这里插入图片描述

在这里插入图片描述

这里我特意尝试对比一下加密结果是否和抓包得到的结果一致,结果发现完全一致
浏览器抓包截图
在这里插入图片描述

此时我们已经获取了登录所需的所有的参数(execution获取同理lt此处略过)ul是学号长度,pl是密码长度
在这里插入图片描述

此时我们就可以将Data进行发送了。接下来的操作就和其他网站的操作类似了。
在这里插入图片描述

不得不说学校对安全性还是很重视的,老版数字杭电采用的只是将密码进行md5加密,虽然传输的数据即使被截取没办法知道密码是多少但是攻击者就可以通过这个md5值当作密码伪装并成功登录。而新版的数字杭电采用的则是 学号+密码+loginticket 合成一个字符串进行rsa非对称加密,虽然公钥是固定的,但由于loginticket每次都会改变使得即使数据被截取攻击者也没办法伪装。

长整数四则运算_双向循环链表

长整数四则运算_双向循环链表

[ 问题描述 ]
设计程序实现两个任意长整数的求和运算。
[ 基本要求 ]
利用双向循环链表实现长整数的存储, 每个结点含一个整型变量. 任何整型变量的范围是 -(215-1)~(215-1)。输入和输出形式: 按中国对于长整数的表
示习惯, 每四位一组,组间用逗号隔开。
[ 测试数据 ]
(1) 0;0;应输出”0”。
(2) -2345,6789;-7654,3211; 应输出”-1,0000,0000”。
(3) -9999,9999; 1,0000,0000,0000; 应输出”9999,0000,0001”。
(4) 1,0001,0001; -1,0001,0001; 应输出”0”。
(5) 1,0001,0001; -1,0001,0000; 应输出”1”。
[ 实现提示 ]
(1) 每个结点可以存放的最大整数为 215-1 = 32767 才能保证两数相加不会溢出。但若这样存,即相当于按 32768 进制数存,在十进制数与32768 进制数间
的转换十分不方便,故可以在每个结点中仅存十进制数的4 位,即不超过9999的非负整数, 整个链表被视为万进制。
(2)可以利用头结点数据域的符号代表长整数的符号。 用其绝对值表示元素结点数目。相加过程中不要破坏两个操作数链表。两操作数的头指针存于指针数
组中是简化程序结构的一种方法。不能给长整数位数规定上限。

vs2019代码

代码片.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
// An highlighted block
// ConsoleApplication10.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

typedef struct Node {
int num;
struct Node* prior;
struct Node* next;

}list;

char init(list* body, char ch, int ten) {

if (ch == ',') {
return',';
}
else if (ch >= '0' && ch <= '9')
{

int x = int(ch - '0');
body->num = body->num + x * ten;

scanf_s("%c",&ch);
if (ch == ',')body->num /= ten;
if (ch == ';') {
body->num /= ten;
return ';';
}
ten /= 10;
init(body, ch, ten);
}

}

list * xiangjia(list * head, list * head1, list * head2) {
int a1 = head1->num;
int a2 = head2->num;
int flag=1;
while (head1->next!=NULL)
{
head1 = head1->next;
}
while (head2->next != NULL)
{
head2 = head2->next;
}
while (head1->prior != NULL && head2->prior != NULL)
{
head->num = a1*(head1->num) + a2*(head2->num) + head->num;

head->prior = (list*)malloc(sizeof(list));
head->prior->num = 0;
if (head->num >= 0) {
flag = 1;
if (head->num >= 10000) {
head->prior->num = 1;
head->num -= 10000;
}

}else if (head->num < 0) {
flag = -1;
if (head1->prior->prior == NULL && head2->prior->prior == NULL && head->num<10000&&head->num>-10000) {
head->num = -1 * (head->num);
}
else {
head->prior->num = -1;
head->num += 10000;
head->num = -1 * (head->num);
}
}



head->prior->next = head;
head = head->prior;
head1 = head1->prior;
head2 = head2->prior;
}
while (head1->prior != NULL)
{
//flag = 1;
head->num = a1*(head1->num) + head->num;
head->prior = (list*)malloc(sizeof(list));
head->prior->num = 0;
if (head->num >= 10000) {
head->prior->num = 1;
head->num -= 10000;
}
else if (head->num <= -10000) {
head->prior->num = -1;
head->num += 10000;
}
else head->prior->num = 0;
if (head->num >= 0) {
flag = 1;
}else if (head->num < 0) {
flag = -1;
head->num = -1 * (head->num);
head->num = -1 * (head->num);
}

head->prior->next = head;
head = head->prior;
head1 = head1->prior;
}
while (head2->prior != NULL)
{
//flag = 1;
head->num = a2*(head2->num) + head->num;

head->prior = (list*)malloc(sizeof(list));
head->prior->num = 0;
if (head->num >= 0) {
flag = 1;
if (head->num >= 10000) {
head->prior->num = 1;
head->num -= 10000;
}

}
else if (head->num < 0) {
flag = -1;
if (head2->prior->prior == NULL) {
head->num = -1 * (head->num);
}
else {
head->prior->num = -1;
head->num += 10000;
head->num = -1 * (head->num);
}
}

head->prior->next = head;
head2 = head2->prior;
//if (head->num == 0 && head2->prior == NULL && head->prior==0 )return head;
head = head->prior;

}

if (head->num != 0) {
if (head->num < 0)head->num = -1 * (head->num);
head->prior = (list*)malloc(sizeof(list));
head->prior->next = head;
head = head->prior;

}

head->num = flag;

return head;

}

void creatlist(list * head) {
char ch;
int ten = 1000;
list* body = (list*)malloc(sizeof(list));
head->next = body;
body->prior = head;
body->num = 0;
body->next = NULL;

scanf_s("%c", &ch);
if (ch == '-') {
head->num = -1;
scanf_s("%c", &ch);
}
if (ch ==';')
return;


char result=init(body, ch, ten);
if (result == 59)
return;

creatlist(body);


}

void printout(list* p) {

if (p->num == -1)printf("-");
while (p->next->num == 0 && p->next->next != NULL) {
p = p->next;
p->prior = NULL;
}
while (p->next != NULL)
{
p = p->next;
int cnt = 0;
if (p->prior->prior != NULL&&p->num!=0){
int x = p->num;
for (cnt = 0; x != 0; cnt++) {
x /= 10;
}
for (int i = 0; i < 4 - cnt; i++)printf("0");
}
else if(p->prior->prior != NULL && p->num==0)
{
printf("000");
}
printf("%d", p->num);
if (p->next != NULL)printf(",");
}
}
int main() {

list* head = (list*)malloc(sizeof(list));
head->next = NULL;
head->num = 0;
list* head1 = (list*)malloc(sizeof(list));
head1->prior = NULL;
head1->num = 1;
list* head2 = (list*)malloc(sizeof(list));
head2->prior = NULL;
head2->num = 1;
creatlist(head1);
creatlist(head2);

list* p = xiangjia(head, head1, head2);
p->prior = NULL;
printout(p);

return 0;
}



  • Copyrights © 2015-2020 Kenton Lee
  • Visitors: | Views:

请我喝杯咖啡吧~

支付宝
微信