ﺩﺭﺱ ﺳﻴﺴﺘﻢﻫﺎﯼ ﻋﺎﻣﻞ )ﺩﻛﺘﺮ ﺟﻠﻴﻠﻲ( ﭘﺎﻳﻴﺰ ۱۳۸۶ ﺗﻤﺮﻳﻦ ﮐﺎﻣﭙﻴﻮﺗﺮﯼ ۲ ﺗﺎﺭﻳﺦ ﺗﺤﻮﻳﻞ :ﺳﻪ ﺷﻨﺒﻪ ۱۳۸۶/۹/۲۰ ﻧﮑﺎﺕ ﻗﺎﺑﻞ ﺗﻮﺟﻪ .۱ﺗﻤﺮﻳﻦﻫﺎﯼ ﮐﺎﻣﭙﻴﻮﺗﺮﯼ ﺑﺎﻳﺪ ﺩﺭ ﮔﺮﻭﻩﻫﺎﯼ ﺩﻭ ﻧﻔﺮﻩ ﺍﻧﺠﺎﻡ ﺷﻮﺩ. .۲ﺑﺮﻧﺎﻣﻪﻫﺎ ﺑﺎﻳﺪ ﺩﺭ ﻣﺤﻴﻂ ﻟﻴﻨﻮﮐﺲ ﻭ ﺑﺎ ﺯﺑﺎﻥ C/C++ﻧﻮﺷﺘﻪ ﺷﻮﻧﺪ. .۳ﺍﺳﺘﻔﺎﺩﻩ ﺍﺯ Makefileﺑﺮﺍﯼ ﺳﺎﺧﺖ ﺑﺮﻧﺎﻣﻪﻫﺎ ﺍﻟﺰﺍﻣﯽ ﺍﺳﺖ .ﺍﻃﻼﻋﺎﺕ ﻣﺮﺑﻮﻁ ﺑﻪ ﻧﻮﺷﺘﻦ Makefileﺩﺭ ﺑﺨﺶ ﻣﻨﺎﺑﻊ ﻭﺏﺳﺎﻳﺖ ﺩﺭﺱ ﻣﻮﺟﻮﺩ ﺍﺳﺖ. .۴ﺗﻤﺎﺭﻳﻦ ﺑﺎﻳﺪ ﺗﺎ ﭘﺎﻳﺎﻥ ﻭﻗـﺖ ﺗﻌﻴـﻴﻦ ﺷـﺪﻩ ،ﺑـﻪ ﺁﺩﺭﺱ ce424-owner@lists.ce.sharif.eduﻓﺮﺳـﺘﺎﺩﻩ ﺷﻮﻧﺪ. ﻋﻨﻮﺍﻥ ﻣﻴﻞ CA2 : ﺫﮐﺮ ﻧﺎﻡ ﻭ ﻧﺎﻡ ﺧﺎﻧﻮﺍﺩﮔﯽ ﻭ ﺷﻤﺎﺭﻩ ﺩﺍﻧﺸﺠﻮﻳﻲ ﺩﺭ ﻣﺘﻦ ﻧﺎﻣﻪ ﺍﻟﺰﺍﻣﯽ ﺍﺳﺖ. ﻣﺘﻦ ﺑﺮﻧﺎﻣﻪ ﺑﻪ ﺻﻮﺭﺕ zipﺷﺪﻩ ﻭ ﻓﺮﻣﺖ ) (family1_family2.zipﭘﻴﻮﺳﺖ ﺷﻮﺩ. .۵ﺗﻨﻬــﺎ ﺩﺭ ﺻــﻮﺭﺕ ﺑــﺮﻭﺯ ﻣــﺸﻜﻞ ﺩﺭ ﻓﺮﺳــﺘﺎﺩﻥ ﺗﻤــﺎﺭﻳﻦ ﺑــﻪ ﺁﺩﺭﺱ ﻓــﻮﻕ ،ﻣــﻲﺗﻮﺍﻧﻴــﺪ ﺁﻥ ﺭﺍ ﺑــﻪ ﺁﺩﺭﺱ ce424s86@gmail.comﺑﻔﺮﺳﺘﻴﺪ. ﺍﻟﻒ .ﺍﺟﺮﺍﻱ ﺩﺳﺘﻮﺭﺍﺕ ﺧﺎﺭﺟﻲ ) (External Commandsﺩﺭ ﭘﻮﺳﺘﻪ )(Shell ﻫﻤﺎﻧﻄﻮﺭ ﻛﻪ ﻣﻲﺩﺍﻧﻴﺪ ،ﭘﻮﺳﺘﻪ ﻳﻚ ﺩﺳﺘﻪ ﺩﺳﺘﻮﺭﺍﺕ ﺩﺍﺧﻠﻲ ﻭ ﻳـﻚ ﺩﺳـﺘﻪ ﺩﺳـﺘﻮﺭﺍﺕ ﺧـﺎﺭﺟﻲ ﺩﺍﺭﺩ .ﺩﺳـﺘﻮﺭﺍﺕ ﺩﺍﺧﻠـﻲ ﺁﻧﻬﺎﻳﻲ ﻫﺴﺘﻨﺪ ﻛﻪ ﺗﻮﺳﻂ ﺧﻮﺩ ﭘﻮﺳﺘﻪ ﭘﻴﺎﺩﻩﺳﺎﺯﻱ ﻣﻲﺷﻮﻧﺪ ﻭ ﺩﺳﺘﻮﺭﺍﺕ ﺧﺎﺭﺟﻲ ﺁﻧﻬﺎﻳﻲﺍﻧﺪ ﻛﻪ ﻣﻮﺟـﺐ ﺍﺟـﺮﺍﻱ ﻣـﺴﺘﻘﻴﻢ ﺑﺮﻧﺎﻣﻪﻫﺎﻱ ﺍﺟﺮﺍﻳﻲ ﺩﻳﮕﺮ ﻣﻲﺷﻮﻧﺪ .ﺑﻪ ﭘﻮﺳﺘﻪﻱ ﻧﻮﺷﺘﻪ ﺷﺪﻩ ﺩﺭ ﺗﻤﺮﻳﻦ ﻛﺎﻣﭙﻴﻮﺗﺮﻱ ﺷﻤﺎﺭﻩﻱ ،۱ﺍﻣﻜﺎﻥ ﺍﺟـﺮﺍﻱ ﺩﺳـﺘﻮﺭﺍﺕ ﺧﺎﺭﺟﻲ ﺭﺍ ﻧﻴﺰ ﺍﺿﺎﻓﻪ ﻛﻨﻴﺪ .ﭘﻮﺳﺘﻪ ﺑﺎﻳﺴﺘﻲ ﺍﻣﻜﺎﻥ ﺍﺟﺮﺍﻱ ﺩﺳـﺘﻮﺭﺍﺕ ﺧـﺎﺭﺟﻲ ﺭﺍ ﺩﺭ backgroundﻫـﻢ ﺩﺍﺷـﺘﻪ ﺑﺎﺷـﺪ. ﺑﺪﻳﻦ ﻣﻌﻨﺎ ﻛﻪ ﻭﻗﺘﻲ ﭘﻮﺳﺘﻪ ﺩﺭ ﺣﺎﻝ ﺍﺟﺮﺍﻱ ﻳﻚ ﺩﺳﺘﻮﺭ ﺍﺳﺖ ،ﺑﺘﻮﺍﻧﺪ ﺑﺪﻭﻥ ﻣﻨﺘﻈﺮ ﻣﺎﻧﺪﻥ ﺑﺮﺍﻱ ﺍﺗﻤﺎﻡ ﺁﻥ ،ﺩﺳﺘﻮﺭ ﺑﻌﺪﻱ ﺭﺍ ﻧﻴﺰ ﺍﺟﺮﺍ ﻧﻤﺎﻳﺪ. Example of executing normally: /home/SHMB/ >> cmd arg1 arg2 … argn >> cp –r /root/temp.txt Example of executing in background: & >> cmd arg1 arg2 … argn >> cp –r /root/temp.txt & /home/SHMB/ -١- ﺭﺍﻫﻨﻤﺎﻳﻲ: • ﻧﺴﺨﻪﻱ ﺳﻮﻡ manﺳﻴﺴﺘﻢ ﻋﺎﻣﻞ ﻟﻴﻨﻮﻛﺲ ﻣﺮﺑﻮﻁ ﺑﻪ ﺩﺳﺘﻮﺭ .(man 3 exec) exec • ﻓﺎﻳﻞ manﻣﺮﺑﻮﻁ ﺑﻪ ﺩﺳﺘﻮﺭ .fork • ﻣﻄﺎﻟﻌﻪﻱ ﻓﺼﻞ ۱۱ﻛﺘﺎﺏ ،Linux-Programming-Unleashedﻗﺴﻤﺖ System calls and .library function ﺏ .ﺁﺷﻨﺎﻳﻲ ﺑﺎ IPCﻭ Signaling ﻣﻲﺧﻮﺍﻫﻴﻢ ﻳﻚ ﺩﺳﺘﻮﺭ ﺩﺍﺧﻠﻲ ﺑﻪ ﻧﺎﻡ historyﺑﻪ ﭘﻮﺳﺘﻪﻱ ﺗﻤﺮﻳﻦ ۱ﺑﻴﻔﺰﺍﻳﻴﻢ ﻛﻪ Nﺩﺳﺘﻮﺭ ﺁﺧـﺮ ﺍﺟـﺮﺍ ﺷـﺪﻩ ﺗﻮﺳـﻂ ﻛﺎﺭﺑﺮ ﺭﺍ ﺑﻪ ﻣﺎ ﻧﺸﺎﻥ ﻣﻲﺩﻫﺪ .ﺑﻪ ﺩﻻﻳﻠﻲ ﻧﻤﻲﺧﻮﺍﻫﻴﻢ ﻛﻪ ﺍﻳﻦ ﻟﻴﺴﺖ ﺩﺳﺘﻮﺭﺍﺕ ﺩﺭ ﺧﻮﺩ ﭘﺮﺩﺍﺯﻩﻱ shellﻧﮕﻬـﺪﺍﺭﻱ ﺷـﻮﺩ. ﺑﻪ ﺟﺎﻱ ﺁﻥ ﻳﻚ ﺑﺮﻧﺎﻣﻪ ﺑﻪ ﻧﺎﻡ loggerﺑﺎﻳﺪ ﻧﻮﺷﺘﻪ ﺷﻮﺩ ﻛﻪ ﺍﻳـﻦ ﻟﻴـﺴﺖ ﺭﺍ ﺩﺭ ﺧـﻮﺩ ﻧﮕـﻪ ﺩﺍﺭﺩ ﻭ ﺳـﺮﻭﻳﺲﻫـﺎﻳﻲ ﺑـﺮﺍﻱ ﺑﺎﺯﻳﺎﺑﻲ ﺁﻧﻬﺎ ﺍﺭﺍﺋﻪ ﺩﻫﺪ. ﺑﻪ ﺍﻳﻦ ﻣﻨﻈﻮﺭ ،ﺩﺭ ﺑﺮﻧﺎﻣﻪﻱ ﭘﻮﺳﺘﻪ ،ﭘﺲ ﺍﺯ ﻫﺮ ﺩﺳﺘﻮﺭﻱ ﻛﻪ ﺗﻮﺳـﻂ ﻛـﺎﺭﺑﺮ ﺍﺟـﺮﺍ ﻣـﻲﺷـﻮﺩ ،ﺑـﻪ ﺑﺮﻧﺎﻣـﻪﻱ loggerﻳـﻚ ﺳﻴﮕﻨﺎﻝ ) (signalﺑﻔﺮﺳﺘﻴﺪ ﻛﻪ ﺁﻥ ﺭﺍ ﺍﺯ ﻭﺟﻮﺩ ﻳﻚ ﺩﺭﺧﻮﺍﺳﺖ ﻣﻄﻠﻊ ﻛﻨﺪ .ﺳﭙﺲ ﺑﺎ ﺍﺳﺘﻔﺎﺩﻩ ﺍﺯ ﻳﻜﻲ ﺍﺯ ﺭﻭﺵﻫـﺎﻱ IPC ﻣﺜﻞ ) pipe, shared memory, message passing, etc.ﺍﺯ socket programmingﺍﺳﺘﻔﺎﺩﻩ ﻧﻜﻨﻴﺪ( ،ﻧﺎﻡ ﺩﺳﺘﻮﺭ ﺭﺍ ﺑﻪ loggerﺑﻔﺮﺳﺘﻴﺪ .ﺍﺯ ﻃﺮﻑ ﺩﻳﮕﺮ ،ﺑﺮﻧﺎﻣﻪﻱ loggerﻣﻨﺘﻈﺮ ﻳﻚ ﺳﻴﮕﻨﺎﻝ ﻣـﻲﻣﺎﻧـﺪ ) (waitﻭ ﻫﺮﮔـﺎﻩ ﻛـﻪ ﻳﻚ ﺳﻴﮕﻨﺎﻝ ﺩﺭﻳﺎﻓﺖ ﻛﺮﺩ ﺑﺎ ﺍﺳﺘﻔﺎﺩﻩ ﺍﺯ ،IPCﻧﺎﻡ ﺩﺳﺘﻮﺭ ﻓﺮﺳﺘﺎﺩﻩ ﺷﺪﻩ ﺭﺍ ﺩﺭﻳﺎﻓﺖ ﻣـﻲﻛﻨـﺪ ﻭ ﺩﺭ ﻳـﻚ ﺳـﺎﺧﺘﻤﺎﻥ ﺩﺍﺩﻩ ﺫﺧﻴﺮﻩ ﻣﻲﻛﻨﺪ .ﺑﺮﺍﻱ ﺳﺎﺩﮔﻲ ﺍﻳﻦ ﺳﺎﺧﺘﺎﺭ ﺩﺍﺩﻩ ﻓﺮﺽ ﻛﻨﻴﺪ ﻛﻪ ﺗﻌﺪﺍﺩ ﺩﺳﺘﻮﺭﺍﺕ historyﻣﺤﺪﻭﺩ ﺍﺳﺖ. Example: myshell >> ls . .. temp1 temp2 myshell >> cd temp1 myshell >> history error: there is no logger process running in the system. myshell >> ls . .. shell.cpp shell.h logger myshell >> ./logger myshell >> chertopert error: no such file or directory or command myshell >> cd .. myshell >> ls . .. temp1 temp2 myshell >> history 10 chertopert cd ls history myshell >> history 3 ls history history ﺭﺍﻫﻨﻤﺎﻳﻲ: • ﭼﻮﻥ ﺧﻮﺩ ﭘﻮﺳﺘﻪ ،ﺑﺮﻧﺎﻣﻪﻱ loggerﺭﺍ ﺍﺟﺮﺍ ﻣﻲﻛﻨﺪ ،ﺑﻨﺎﺑﺮﺍﻳﻦ ﻣﻲﺗﻮﺍﻧﺪ ﺑﻪ ﺭﺍﺣﺘﻲ PIDﺁﻥ ﺭﺍ ﺑﺪﺳﺖ ﺁﻭﺭﺩ. • ﻓﺎﻳﻞ manﻣﺮﺑﻮﻁ ﺑﻪ fifoﻭ .(man fifo, man signal) signal • ﻣﻄﺎﻟﻌﻪﻱ ﻗﺴﻤﺖﻫﺎﻱ ﻣﺮﺑﻮﻁ ﺑﻪ IPCﺩﺭ ﻛﺘﺎﺏ .Linux-Programming-Unleashed -٢-
© Copyright 2025 Paperzz