2021-2022-1 20211306《信息安全专业导论》第九周学习总结

2021-2022-1 20211306《信息安全专业导论》第9周学习总结

作业信息

|这个作业属于哪个课程|https://edu.cnblogs.com/campus/besti/2021-2022-1fois
|这个作业要求在哪里|https://www.cnblogs.com/rocedu/p/9577842.html#WEEK09
|这个作业的目标|<操作系统责任
内存与进程管理
分时系统
CPU调度
文件、文件系统
文件保护
磁盘调度>
|作业正文|

教材学习内容总结

《计算机科学概论》

  • 分时系统 更大程度地利用机器的能力和速度,每个用户不用竞争资源,只有一个用户坐在计算机前,而其它用户可以用其他计算机通过网络连接到这台计算机上。
  • CPU调度 是多道程序操作系统的基础。通过在进程间切换CPU,操作系统可以使得计算机更加高效。通过CPU调度算法决定将CPU给予哪个进程,以便能够运行。
  • 非抢先调度 当当前执行的进程自愿放弃CPU发生的调度
  • 抢先调度 当操作系统决定照顾另一个进程而抢占当前执行进程的CPU资源时的调度。
  • 文件、文件系统 文件系统是操作系统用于明确存储设备或分区上的文件的方法和数据结构;即在存储设备上组织文件的方法。负责为用户建立文件,存入、读出、修改、转储文件,控制文件的存取,当用户不再使用时撤销文件等。
  • 文件保护 通过文件加锁或访问权限控制,防止文件被破坏或不当访问的过程。
  • 磁盘调度算法 先到先服务(FCFS):进程按照他们到达运行状态的顺序转移到CPU,是非抢先的。FCFS算法不能帮助确定最佳的进程调度顺序;最短作业优先(SJN)基于未来信息,其确定的执行时间基本不能确定,而且若估算错误,算法前提会崩溃。

《看漫画学python》

点击查看代码
f = open('test.txt', 'w+')
f.write('World') 
print('1.创建test.txt文件,World写入文件') 

f = open('test.txt', 'r+')
f.write('Hello')
print('2.打开test.txt文件,Hello覆盖文件内容')

f = open('tset.txt','a')
f.write(' ')
print(r'3.打开test.txt文件,在文件尾部追加空格" "')

fname = 'C:/Users/Lenovo/Desktop/py/test.txt'
f = open(fname, 'a+')
f.write('World')
print('4.打开test.txt文件,在文件尾部追加World')

f_name ='test.txt'
f = None
try:
    f = open(f_name)
    print('打开文件成功')
    content = f.read()
    print(content)
except FileNotFoundError as e:
    print('文件不存在,请先使用ch12_1.py程序创建文件')
except OSError as e:
    print('处理OSError异常')
finally:	 	
 	if f is not None:	 	
 	    f.close()	
 	    print('关闭文件成功')	
      
f_name = 'test.txt'
with open(f_name) as f:
    content = f.read()
    print(content)


f_name = 'src_file.txt'

with open(f_name, 'r', encoding='gbk') as f:
    lines = f.readlines()
    copy_f_name = 'dest_file.txt'
    with open(copy_f_name, 'w', encoding='utf-8') as copy_f:
        copy_f.writelines(lines)
        print('文件复制成功')


f_name = 'logo.png'

with open(f_name, 'rb') as f:
    b = f.read()
    copy_f_name = 'logo2.png'
    with open(copy_f_name, 'wb') as copy_f:
        copy_f.write(b)
        print('文件复制成功')
        
        
import threading

t = threading.current_thread

print(t.name)
print(threading.active_count())
t = threading.main_thread()        
print(t.name)

import time

def thread_body():
    t = threading.current_thread()
    for n in range(5):
        print('第{0}次执行线程{1}'.format(n,t.name))
        time.sleep(2)
    print('线程{0}执行完成!'.format(t.name))
    
class SmallThread(threading.Thread):
    def __int__(self, name=None):
        super().__init__(name=name)
    def run(self):
        t = threading.current_thread()
        for n in range(5):
            print('第{0}次执行线程{1}'.format(n, t.name))
            time.sleep(2)
        print('线程{0}执行完成!'.format(t.name))
t1 = SmallThread()
t2 = SmallThread(name='Mythread')
t1.start()
t2.start()

value = []
def thread_body():
    print('t1子线程开始...')
    for n in range(2):
        print('t1子线程执行...')
        value.append(n)
        time.sleeap(2)
    print('t1子线程结束。') 
print('主线程开始执行...')
t1 = threading.Thread(target=thread_body)
t1.start()
t1.join()
print('value = {0}'.format(value))
print('主线程继续执行...')


import threading
import time

isrunning = True
def workthread_body():
    while isrunning: 	
        print('工作线程执行中...')
        time.sleep(5)
    print('工作线程结束。')
def	controlthread_body():
    global isrunning
    while isrunning: 	

        command = input('请输入停止指令:')
        if command == 'exit':	
 	        isrunning = False
            print('控制线程结束。')	
workthread = threading.Thread(target=workthread_body)	
 	 	
workthread.start()	
controlthread = threading.Thread(target=controlthread_body)
controlthread.start()


import threading
import time
import urllib.request
isrunning = True
def workthread_body():
    while isrunning:
        print('工作线程执行下载任务...')
        download()
        time.sleep(5)
    print('工作线程结束。')
def controlthread_body():
    global isrunning
    while isrunning:
        command = input('请输入停止指令:')
        if command == 'exit':
            isrunning= False
            print('控制线程结束。')	

def download():
    url = 'http://localhost:8080/NoteWebService/logo.png'	
    reg = urllib.request.Request(url)
    with urllib.request.urlopen(url) as response:
        data = response.read()
        f_name = 'download.png'
        with open(f_name, 'wb') as f:
            f.write(data)
            print('下载文件成功')
workthread = threading.Thread(target=workthread_body) 
workthread.start()
controlthread = threading.Thread(target=controlthread_body)
controlthread.start()

代码调试中的问题和解决过程

  • 问题1:常出现语法错误
  • 问题1解决方案:不断检查对照课本内容,并牢记各种语句的固定格式
  • 问题2:出现IndentationError: unindent does not match any outer indentation level
  • 问题2解决方案:上网搜索相关资料,发现在新版python中tap和space不能混用,找到了出错的行并加以改正

学习进度条

代码行数(新增/累积) 博客量(新增/累积) 学习时间(新增/累积) 重要成长
目标 5000行 30篇 400小时
第一周 150/150 2/2 20/20
第二周 150/300 2/4 18/38
...... ...... ...... ......
第九周 600/2000 3/19 20/160
posted @ 2021-11-21 22:32  20211306丁文博  阅读(21)  评论(0编辑  收藏  举报