重走傻屄憨鳩路。當年楊X偉讓我們在Unix(用IBM-PC/AT機上的Xinex冒充)
演示進程間用“信號燈”進行同步。當時就做不出來。當時連C語言都不理解,全局變
量是什麼意思都不懂。做條毛啊。計算機系的一群傻屄憨鳩拿着紗紙還真以為自己學
習成績“很”好。還是岑某文書記利害,根本不用學計算機,憑馬克思主義“放豬四海
皆準”的宇宙真理一眼就看穿你們這幫孫子學習成績都不是“很”好。不但你們學習
成績不是“很”好,你們的學校的水平還“很”不高。楊X偉還狗屁“很”不通。
現在還是做不出來。因為Unixv6根本不提供“信號燈”,我們的用戶程序的邏輯空間
是相互獨立的,我們的用戶程序運行在非特權處理機狀態,不能屏蔽中斷。總之,這題
在Unixv6上根本做不出來。
現在想了想,應當可以用兩個pipe來同步兩個進程。
當然如果用個很高級的技巧,利用文件緩衝塊是共享的這一點,可以有沒有屏蔽中斷
的非特權處理機狀態下實現信號燈的。這個是我當年在美國上學時從一本日本人寫
的操作系統的書上學到的。不過效率極低,沒啥實用價值。可以用來玩一玩。這個技
巧,我小時候坐車到縣城過盤山公路時發現司機都懂(有一段路每次只能過一輛車,
其他車只能在山下等,否則對向的車開到山頂鬥牛,誰都過不了,其中一輛車要倒車
下山,更加危險)。毛主席說過:高貴者最愚蠢,我敢說,這裡的電民,學位一堆,要是
沒看過日本人的那本書或者看過沒留神,多數不會。哈哈。
有些軍事五毛要跳出來裝神弄鬼,說我上學的學校在中國是最差的,別的學校滿櫃都
是“土楞獎”的獎章我沒機會看而已。中國做不出CPU和OS是故意不做,不是水平低
做不出來。哈哈。
以下是兩個進程竟爭電傳打字機的結果。很奇怪,為何父進程的優先權比子進程高得
多。父進程每次能打一行,而子進程每次只能打一個字符。想不通。看來Unixv6的
優先級設定還是很謊謬的。同樣的兩個進程,爭用同一個資源,為什麼差別這麼大呢。
main()
{
if(fork())
{
execl("parent",0);
}
execl("child",0);
}
main()
{
int count;
count=100;
while(count--)
printf("the parent%d process is running!
",count);
}
main()
{
int count;
count=100;
while(count--)
printf("CHILD_%d
",count);
}
# fork
the parent99 process is running!
the parent98 proCcess is running!
the parent97 prHocess is running!
the parent96 prIocess is running!
the parent95 prLocess is running!
the parent94 prDocess is running!
the parent93 pr_ocess is running!
the parent92 pr9ocess is running!
the parent91 pr9ocess is running!
the parent90 pr
ocess is running!
the parent89 Cprocess is running!
the parent88 prHocess is running!
the parent87 prIocess is running!
the parent86 prLocess is running!
the parent85 prDocess is running!
the parent84 pr_ocess is running!
the parent83 pr9ocess is running!
the parent82 pr8ocess is running!
the parent81 pr
ocess is running!
the parent80 Cprocess is running!
the parent79 prHocess is running!
the parent78 prIocess is running!
the parent77 prLocess is running!
the parent76 prDocess is running!
the parent75 pr_ocess is running!
the parent74 pr9ocess is running!
the parent73 pr7ocess is running!
the parent72 pr
ocess is running!
the parent71 Cprocess is running!
the parent70 prHocess is running!
the parent69 prIocess is running!
the parent68 prLocess is running!
the parent67 prDocess is running!
the parent66 pr_ocess is running!
the parent65 pr9ocess is running!
the parent64 pr6ocess is running!
the parent63 pr
ocess is running!
the parent62 Cprocess is running!
the parent61 prHocess is running!
the parent60 prIocess is running!
the parent59 prLocess is running!
the parent58 prDocess is running!
the parent57 pr_ocess is running!
the parent56 pr9ocess is running!
the parent55 pr5ocess is running!
the parent54 pr
ocess is running!
the parent53 Cprocess is running!
the parent52 prHocess is running!
the parent51 prIocess is running!
the parent50 prLocess is running!
the parent49 prDocess is running!
the parent48 pr_ocess is running!
the parent47 pr9ocess is running!
the parent46 pr4ocess is running!
the parent45 pr
ocess is running!
the parent44 Cprocess is running!
the parent43 prHocess is running!
the parent42 prIocess is running!
the parent41 prLocess is running!
the parent40 prDocess is running!
the parent39 pr_ocess is running!
the parent38 pr9ocess is running!
the parent37 pr3ocess is running!
the parent36 pr
ocess is running!
the parent35 Cprocess is running!
the parent34 prHocess is running!
the parent33 prIocess is running!
the parent32 prLocess is running!
the parent31 prDocess is running!
the parent30 pr_ocess is running!
the parent29 pr9ocess is running!
the parent28 pr2ocess is running!
the parent27 pr
ocess is running!
the parent26 Cprocess is running!
the parent25 prHocess is running!
the parent24 prIocess is running!
the parent23 prLocess is running!
the parent22 prDocess is running!
the parent21 pr_ocess is running!
the parent20 pr9ocess is running!
the parent19 pr1ocess is running!
the parent18 pr
ocess is running!
the parent17 Cprocess is running!
the parent16 prHocess is running!
the parent15 prIocess is running!
the parent14 prLocess is running!
the parent13 prDocess is running!
the parent12 pr_ocess is running!
the parent11 pr9ocess is running!
the parent10 pr0ocess is running!
the parent9 pro
cess is running!
the parent8 prCocess is running!
the parent7 procHess is running!
the parent6 procIess is running!
the parent5 procLess is running!
the parent4 procDess is running!
the parent3 proc_ess is running!
the parent2 proc8ess is running!
the parent1 proc9ess is running!
the parent0 proc
ess is running!
CHILD_88
CH#I LD_87
CHILD_86
CHILD_85
CHILD_84
CHILD_83
CHILD_82
CHILD_81
CHILD_80
CHILD_79
CHILD_78
CHILD_77
CHILD_76
CHILD_75
CHILD_74
CHILD_73
CHILD_72
CHILD_71
CHILD_70
CHILD_69
CHILD_68
CHILD_67
CHILD_66
CHILD_65
CHILD_64
CHILD_63
CHILD_62
CHILD_61
CHILD_60
CHILD_59
CHILD_58
CHILD_57
CHILD_56
CHILD_55
CHILD_54
CHILD_53
CHILD_52
CHILD_51
CHILD_50
CHILD_49
CHILD_48
CHILD_47
CHILD_46
CHILD_45
CHILD_44
CHILD_43
CHILD_42
CHILD_41
CHILD_40
CHILD_39
CHILD_38
CHILD_37
CHILD_36
CHILD_35
CHILD_34
CHILD_33
CHILD_32
CHILD_31
CHILD_30
CHILD_29
CHILD_28
CHILD_27
CHILD_26
CHILD_25
CHILD_24
CHILD_23
CHILD_22
CHILD_21
CHILD_20
CHILD_19
CHILD_18
CHILD_17
CHILD_16
CHILD_15
CHILD_14
CHILD_13
CHILD_12
CHILD_11
CHILD_10
CHILD_9
CHILD_8
CHILD_7
CHILD_6
CHILD_5
CHILD_4
CHILD_3
CHILD_2
CHILD_1
CHILD_0
#