一:程序的建立
1,系統的初始化
2,乙個程序在執行過程中開啟了子程序
3,使用者的互動式請求,而建立乙個新程序(如雙擊qq)
4,乙個批處理作業的初始化(只在大型機的批處理系統中應用)
關於程序的建立,unix和windows
1,在unix中系統呼叫的是:fork,fork會建立乙個與父程序一摸一樣的副本
2,在windows中該系統呼叫是:cresteprocess ,既負責處理程序的建立 ,也負責把正確的程式裝入新程序
二:程序的終止:
1,正常退出
2,出錯退出
3,嚴重錯誤(非自願,執行非法指令,如引用不存在的記憶體,i/o等,可以捕捉異常
4,被其他程序殺死
三:程序的層次結構
無論是unix還是windows,程序只有乙個父程序,不同的是:
1,在unix中所有的程序,都是以init程序為根,組成樹形結構。父子程序共同組成乙個程序組
2,windows中,沒有程序層次的概念,所有的程序地位都相同
四:程序的狀態
程序主要分為三種狀態,執行態,阻塞態,就緒態。
五:建立程序的兩種方式
# # # 方式一:
# from multiprocessing import process
# import time
## def task(x):
# print('%s is running' %x)
# time.sleep(3)
# print('%s is done' %x)
## if __name__ == '__main__':
# # process(target=task,kwargs=)
# p=process(target=task,args=('子程序',)) # 如果args=(),括號內只有乙個引數,一定記住加逗號
# p.start() # 只是在作業系統傳送乙個開啟子程序的訊號
## print('主')
# 方式二:
# from multiprocessing import process
# import time
## class myprocess(process):
# def __init__(self,x):
# super().__init__()
# self.name=x
## def run(self):
# print('%s is running' %self.name)
# time.sleep(3)
# print('%s is done' %self.name)
## if __name__ == '__main__':
# p=myprocess('子程序1')
# p.start() #p.run()
# print('主')
六:程序之間相互隔離:
python建立程序的兩種方式
執行緒內的任務不會同時執行,可以解決的方法是在每個程序裡面執行乙個執行緒,可以實現。gil的限制 multiprocessing管理程序的包,threading.thread用來管理執行緒 程序可以解決併發,但是相關的訊息無法互動,需要借助別的例如pipe和queue 但是在使用的時候仍有資源的消耗...
Python中建立程序的兩種方式以及程序池
在python中建立程序有兩種方式,第一種是 from multiprocessing import process import time def test while true print test time.sleep 1 if name main p process target test ...
python 多程序的兩種建立方式
python中使用執行緒有兩種方式 函式或者用類來包裝執行緒物件。第一種 函式 import time import threading defcoding for x in range 3 print 正在寫 s threading.current thread 獲取程序名字 time.sleep...