辅导案例-Y 3

欢迎使用51辅导,51作业君孵化低价透明的学长辅导平台,服务保持优质,平均费用压低50%以上! 51fudao.top
Avvignmen| ƒĹ vmaѴѴvh ŐPouoѴio Avvignmen|ő
Due NoY 3 b\ 11:59pm Points 180 Submitting a file Xpload File T\pes ]ip
AYailable OcW 20 aW 8am - NoY 5 aW 11:59pm 17 Ga\V
S†bmi| Avvignmen|
In|uod†cঞon
In WhiV aVVignmenW \oX Zill ZUiWe smallsh \oXU oZn Vhell in C. VmallVh Zill implemenW a VXbVeW of feaWXUeV of
Zell-knoZn VhellV, VXch aV baVh. YoXU pUogUam Zill
1. PUoYide a pUompW foU UXnning commandV
2. Handle blank lineV and commenWV, Zhich aUe lineV beginning ZiWh Whe # chaUacWeU
3. PUoYide e[panVion foU Whe YaUiable $$
4. E[ecXWe 3 commandV e[iW , cd , and VWaWXV Yia code bXilW inWo Whe Vhell
5. E[ecXWe oWheU commandV b\ cUeaWing neZ pUoceVVeV XVing a fXncWion fUom Whe e[ec famil\ of fXncWionV
6. SXppoUW inpXW and oXWpXW UediUecWion
7. SXppoUW UXnning commandV in foUegUoXnd and backgUoXnd pUoceVVeV
8. ImplemenW cXVWom handleUV foU 2 VignalV, SIGINT and SIGTSTP
Leauning O†|comev
AfWeU VXcceVVfXl compleWion of WhiV aVVignmenW, \oX VhoXld be able Wo do Whe folloZing
DeVcUibe Whe Uni[ pUoceVV API (ModXle 4, MLO 2)
WUiWe pUogUamV XVing Whe Uni[ pUoceVV API (ModXle 4, MLO 3)
E[plain Whe concepW of VignalV and WheiU XVeV (ModXle 5, MLO 2)
WUiWe pUogUamV XVing Whe Uni[ API foU Vignal handling (ModXle 5, MLO 3)
E[plain I/O UediUecWion and ZUiWe pUogUamV WhaW can emplo\ I/O UediUecWion (ModXle 5, MLO 4)
Puoguam F†ncঞonaѴi|‹
Ɛĺ The Command Puomr|
UVe Whe colon : V\mbol aV a pUompW foU each command line.
The geneUal V\nWa[ of a command line iV:
command [aUg1 aUg2 ...] [< inpXW_file] [> oXWpXW_file] [&]
«ZheUe iWemV in VTXaUe bUackeWV aUe opWional.
YoX can aVVXme WhaW a command iV made Xp of ZoUdV VepaUaWed b\ VpaceV.
The Vpecial V\mbolV , and & aUe Uecogni]ed, bXW Whe\ mXVW be VXUUoXnded b\ VpaceV like oWheU ZoUdV.
If Whe command iV Wo be e[ecXWed in Whe backgUoXnd, Whe laVW ZoUd mXVW be &. If Whe & chaUacWeU appeaUV
an\ZheUe elVe, jXVW WUeaW iW aV noUmal We[W.
If VWandaUd inpXW oU oXWpXW iV Wo be UediUecWed, Whe > oU < ZoUdV folloZed b\ a filename ZoUd mXVW appeaU
afWeU all Whe aUgXmenWV. InpXW UediUecWion can appeaU befoUe oU afWeU oXWpXW UediUecWion.
YoXU Vhell doeV noW need Wo VXppoUW an\ TXoWing; Vo aUgXmenWV ZiWh VpaceV inVide Whem aUe noW poVVible.
We aUe alVo noW implemenWing Whe pipe "_" opeUaWoU.
YoXU Vhell mXVW VXppoUW command lineV ZiWh a ma[imXm lengWh of 2048 chaUacWeUV, and a ma[imXm of
512 aUgXmenWV.
YoX do noW need Wo do an\ eUUoU checking on Whe V\nWa[ of Whe command line.
Ƒĺ Commen|v ş BѴank Linev
YoXU Vhell VhoXld alloZ blank lineV and commenWV.
An\ line WhaW beginV ZiWh Whe # chaUacWeU iV a commenW line and VhoXld be ignoUed. Mid-line commenWV,
VXch aV Whe C-VW\le //, Zill noW be VXppoUWed.
A blank line (one ZiWhoXW an\ commandV) VhoXld alVo do noWhing.
YoXU Vhell VhoXld jXVW Ue-pUompW foU anoWheU command Zhen iW UeceiYeV eiWheU a blank line oU a commenW
line.
ƒĺ EŠranvion of VauiabѴe ŪŪ
YoXU pUogUam mXVW e[pand an\ inVWance of "$$" in a command inWo Whe pUoceVV ID of Whe VmallVh iWVelf. YoXU
Vhell doeV noW oWheUZiVe peUfoUm YaUiable e[panVion.
Ɠĺ B†iѴ|Ŋin Commandv
YoXU Vhell Zill VXppoUW WhUee bXilW-in commandV: e[iW , cd , and VWaWXV . TheVe WhUee bXilW-in commandV aUe
Whe onl\ oneV WhaW \oXU Vhell Zill handle iWVelf - all oWheUV aUe Vimpl\ paVVed on Wo a membeU of Whe e[ec()
famil\ of fXncWionV.
YoX do noW haYe Wo VXppoUW inpXW/oXWpXW UediUecWion foU WheVe bXilW in commandV
TheVe commandV do noW haYe Wo VeW an\ e[iW VWaWXV.
If Whe XVeU WUieV Wo UXn one of WheVe bXilW-in commandV in Whe backgUoXnd ZiWh Whe & opWion, ignoUe WhaW
opWion and UXn Whe command in Whe foUegUoXnd an\Za\ (i.e. don'W diVpla\ an eUUoU, jXVW UXn Whe command in
Whe foUegUoXnd).
eŠi|
The e[iW command e[iWV \oXU Vhell. IW WakeV no aUgXmenWV. When WhiV command iV UXn, \oXU Vhell mXVW kill
an\ oWheU pUoceVVeV oU jobV WhaW \oXU Vhell haV VWaUWed befoUe iW WeUminaWeV iWVelf.
cd
The cd command changeV Whe ZoUking diUecWoU\ of VmallVh.
B\ iWVelf - ZiWh no aUgXmenWV - iW changeV Wo Whe diUecWoU\ Vpecified in Whe HOME enYiUonmenW YaUiable
ThiV iV W\picall\ noW Whe locaWion ZheUe VmallVh ZaV e[ecXWed fUom, XnleVV \oXU Vhell e[ecXWable iV
locaWed in Whe HOME diUecWoU\, in Zhich caVe WheVe aUe Whe Vame.
ThiV command can alVo Wake one aUgXmenW: Whe paWh of a diUecWoU\ Wo change Wo. YoXU cd command
VhoXld VXppoUW boWh abVolXWe and UelaWiYe paWhV.
v|a|†v
The VWaWXV command pUinWV oXW eiWheU Whe e[iW VWaWXV oU Whe WeUminaWing Vignal of Whe laVW foUegUoXnd pUoceVV
Uan b\ \oXU Vhell.
If WhiV command iV UXn befoUe an\ foUegUoXnd command iV UXn, When iW VhoXld Vimpl\ UeWXUn Whe e[iW VWaWXV
0.
The WhUee bXilW-in Vhell commandV do noW coXnW aV foUegUoXnd pUoceVVeV foU Whe pXUpoVeV of WhiV bXilW-in
command - i.e., VWaWXV VhoXld ignoUe bXilW-in commandV.
Ɣĺ EŠec†ঞng O|heu Commandv
YoXU Vhell Zill e[ecXWe an\ commandV oWheU Whan Whe 3 bXilW-in command b\ XVing foUk() , e[ec() and
ZaiWpid()
WheneYeU a non-bXilW in command iV UeceiYed, Whe paUenW (i.e., VmallVh) Zill foUk off a child.
The child Zill XVe a fXncWion fUom Whe e[ec() famil\ of fXncWionV Wo UXn Whe command.
YoXU Vhell VhoXld XVe Whe PATH YaUiable Wo look foU non-bXilW in commandV, and iW VhoXld alloZ Vhell VcUipWV
Wo be e[ecXWed
If a command failV becaXVe Whe Vhell coXld noW find Whe command Wo UXn, When Whe Vhell Zill pUinW an eUUoU
meVVage and VeW Whe e[iW VWaWXV Wo 1
A child pUoceVV mXVW WeUminaWe afWeU UXnning a command (ZheWheU Whe command iV VXcceVVfXl oU iW failV).
ѵĺ Inr†| ş O†|r†| Rediuecঞon
YoX mXVW do an\ inpXW and/oU oXWpXW UediUecWion XVing dXp2() . The UediUecWion mXVW be done befoUe XVing
e[ec() Wo UXn Whe command.
An inpXW file UediUecWed Yia VWdin VhoXld be opened foU Ueading onl\; if \oXU Vhell cannoW open Whe file foU
Ueading, iW VhoXld pUinW an eUUoU meVVage and VeW Whe e[iW VWaWXV Wo 1 (bXW don'W e[iW Whe Vhell).
SimilaUl\, an oXWpXW file UediUecWed Yia VWdoXW VhoXld be opened foU ZUiWing onl\; iW VhoXld be WUXncaWed if iW
alUead\ e[iVWV oU cUeaWed if iW doeV noW e[iVW. If \oXU Vhell cannoW open Whe oXWpXW file iW VhoXld pUinW an eUUoU
meVVage and VeW Whe e[iW VWaWXV Wo 1 (bXW don'W e[iW Whe Vhell).
BoWh VWdin and VWdoXW foU a command can be UediUecWed aW Whe Vame Wime (Vee e[ample beloZ).
ƕĺ EŠec†ঞng Commandv in Foueguo†nd ş Backguo†nd
Foueguo†nd Commandv
An\ command ZiWhoXW an & aW Whe end mXVW be UXn aV a foUegUoXnd command and Whe Vhell mXVW ZaiW foU Whe
compleWion of Whe command befoUe pUompWing foU Whe ne[W command. FoU VXch commandV, Whe paUenW Vhell
doeV NOT UeWXUn command line acceVV and conWUol Wo Whe XVeU XnWil Whe child WeUminaWeV.
Backguo†nd Commandv
An\ non bXilW-in command ZiWh an & aW Whe end mXVW be UXn aV a backgUoXnd command and Whe Vhell mXVW
noW ZaiW foU VXch a command Wo compleWe. FoU VXch commandV, Whe paUenW mXVW UeWXUn command line acceVV
and conWUol Wo Whe XVeU immediaWel\ afWeU foUking off Whe child.
The Vhell Zill pUinW Whe pUoceVV id of a backgUoXnd pUoceVV Zhen iW beginV.
When a backgUoXnd pUoceVV WeUminaWeV, a meVVage VhoZing Whe pUoceVV id and e[iW VWaWXV Zill be pUinWed.
ThiV meVVage mXVW be pUinWed jXVW befoUe Whe pUompW foU a neZ command iV diVpla\ed.
If Whe XVeU doeVn'W UediUecW Whe VWandaUd inpXW foU a backgUoXnd command, When VWandaUd inpXW VhoXld be
UediUecWed Wo /deY/nXll
If Whe XVeU doeVn'W UediUecW Whe VWandaUd oXWpXW foU a backgUoXnd command, When VWandaUd oXWpXW VhoXld
be UediUecWed Wo /deY/nXll
Ѷĺ SignaѴv SIGINT ş SIGTSTP
SIGINT
A CTRL-C command fUom Whe ke\boaUd VendV a SIGINT Vignal Wo Whe paUenW pUoceVV and all childUen aW Whe
Vame Wime (WhiV iV a bXilW-in paUW of LinX[).
YoXU Vhell, i.e., Whe paUenW pUoceVV, mXVW ignoUe SIGINT
An\ childUen UXnning aV backgUoXnd pUoceVVeV mXVW ignoUe SIGINT
A child UXnning aV a foUegUoXnd pUoceVV mXVW WeUminaWe iWVelf Zhen iW UeceiYeV SIGINT
The paUenW mXVW noW aWWempW Wo WeUminaWe Whe foUegUoXnd child pUoceVV; inVWead Whe foUegUoXnd child (if
an\) mXVW WeUminaWe iWVelf on UeceipW of WhiV Vignal.
If a child foUegUoXnd pUoceVV iV killed b\ a Vignal, Whe paUenW mXVW immediaWel\ pUinW oXW Whe nXmbeU of
Whe Vignal WhaW killed iW'V foUegUoXnd child pUoceVV (Vee Whe e[ample) befoUe pUompWing Whe XVeU foU Whe
ne[W command.
SIGTSTP
A CTRL-Z command fUom Whe ke\boaUd VendV a SIGTSTP Vignal Wo \oXU paUenW Vhell pUoceVV and all childUen
aW Whe Vame Wime (WhiV iV a bXilW-in paUW of LinX[).
A child, if an\, UXnning aV a foUegUoXnd pUoceVV mXVW ignoUe SIGTSTP.
An\ childUen UXnning aV backgUoXnd pUoceVV mXVW ignoUe SIGTSTP.
When Whe paUenW pUoceVV UXnning Whe Vhell UeceiYeV SIGTSTP
The Vhell mXVW diVpla\ an infoUmaWiYe meVVage (Vee beloZ) immediaWel\ if iW'V ViWWing aW Whe pUompW, oU
immediaWel\ afWeU an\ cXUUenWl\ UXnning foUegUoXnd pUoceVV haV WeUminaWed
The Vhell When enWeUV a VWaWe ZheUe VXbVeTXenW commandV can no longeU be UXn in Whe backgUoXnd.
In WhiV VWaWe, Whe & opeUaWoU VhoXld Vimpl\ be ignoUed, i.e., all VXch commandV aUe UXn aV if Whe\ ZeUe
foUegUoXnd pUoceVVeV.
If Whe XVeU VendV SIGTSTP again, When \oXU Vhell Zill
DiVpla\ anoWheU infoUmaWiYe meVVage (Vee beloZ) immediaWel\ afWeU an\ cXUUenWl\ UXnning foUegUoXnd
pUoceVV WeUminaWeV
The Vhell When UeWXUnV back Wo Whe noUmal condiWion ZheUe Whe & opeUaWoU iV once again honoUed foU
VXbVeTXenW commandV, alloZing Whem Wo be e[ecXWed in Whe backgUoXnd.
See Whe e[ample beloZ foU XVage and Whe e[acW V\nWa[ Zhich \oX mXVW XVe foU WheVe WZo infoUmaWiYe
meVVageV.
SamrѴe Puoguam EŠec†ঞon
HeUe iV an e[ample UXn XVing VmallVh. NoWe WhaW CTRL-C haV no effecW WoZaUdV Whe boWWom of Whe e[ample,
Zhen iW'V XVed Zhile ViWWing aW Whe command pUompW:
$ VmallVh
: lV
jXnk VmallVh VmallVh.c
: lV > jXnk
: VWaWXV
e[iW YalXe 0
: caW jXnk
jXnk
VmallVh
VmallVh.c
: Zc < jXnk > jXnk2
: Zc < jXnk
3 3 23
: WeVW -f badfile
: VWaWXV
e[iW YalXe 1
: Zc < badfile
cannoW open badfile foU inpXW
: VWaWXV
e[iW YalXe 1
: badfile
badfile: no VXch file oU diUecWoU\
: Vleep 5
^CWeUminaWed b\ Vignal 2
: VWaWXV &
WeUminaWed b\ Vignal 2
: Vleep 15 &
backgUoXnd pid iV 4923
: pV
PID TTY TIME CMD
4923 pWV/0 00:00:00 Vleep
4564 pWV/0 00:00:03 baVh
4867 pWV/0 00:01:32 VmallVh
4927 pWV/0 00:00:00 pV
:
: # WhaW ZaV a blank command line, WhiV iV a commenW line
:
backgUoXnd pid 4923 iV done: e[iW YalXe 0
: # Whe backgUoXnd Vleep finall\ finiVhed
: Vleep 30 &
backgUoXnd pid iV 4941
: kill -15 4941
backgUoXnd pid 4941 iV done: WeUminaWed b\ Vignal 15
: pZd
/nfV/VWak/XVeUV/chaXdhUn/CS344/pUog3
: cd
: pZd
/nfV/VWak/XVeUV/chaXdhUn
: cd CS344
: pZd
/nfV/VWak/XVeUV/chaXdhUn/CS344
: echo 4867
4867
: echo $$
4867
: ^C^Z
EnWeUing foUegUoXnd-onl\ mode (& iV noZ ignoUed)
: daWe
Mon Jan 2 11:24:33 PST 2017
: Vleep 5 &
: daWe
Mon Jan 2 11:24:38 PST 2017
: ^Z
E[iWing foUegUoXnd-onl\ mode
: daWe
Mon Jan 2 11:24:39 PST 2017
: Vleep 5 &
backgUoXnd pid iV 4963
: daWe
Mon Jan 2 11:24:39 PST 2017
: e[iW
$
Hin|v ş Revo†ucev
Ɛĺ The Command Puomr|
Be VXUe \oX flXVh oXW Whe oXWpXW bXffeUV each Wime \oX pUinW, aV Whe We[W WhaW \oX'Ue oXWpXWWing ma\ noW Ueach
Whe VcUeen XnWil \oX do in WhiV kind of inWeUacWiYe pUogUam. To do WhiV, call fflXVh() immediaWel\ afWeU each
and eYeU\ Wime \oX oXWpXW We[W.
ConVideU defining a VWUXcW in Zhich \oX can VWoUe all Whe diffeUenW elemenWV inclXded in a command. Then aV
\oX paUVe a command, \oX can VeW Whe YalXe of membeUV of a YaUiable of WhiV VWUXcW W\pe.
Ƒĺ Commen|v ş BѴank Linev
ThiV VhoXld be Vimple.
ƒĺ EŠranvion of VauiabѴe ŪŪ
HeUe aUe e[ampleV Wo illXVWUaWe Whe UeTXiUed behaYioU. SXppoVe Whe pUoceVV ID of VmallVh iV 179. Then
The VWUing foo$$$$ in Whe command iV conYeUWed Wo foo179179
The VWUing foo$$$ in Whe command iV conYeUWed Wo foo179$
Ɠĺ B†iѴ|Ŋin Commandv
IW iV Uecommended WhaW \oX pUogUam Whe bXilW-in commandV fiUVW, befoUe Wackling Whe commandV WhaW UeTXiUe
foUk() , e[ec() and ZaiWpid() .
The bXilW-in commandV don'W VeW Whe YalXe of VWaWXV. ThiV meanV WhaW hoZeYeU \oX aUe keeping WUack of Whe
VWaWXV, don'W change iW afWeU Whe e[ecXWion of a bXilW-in command.
A pUoceVV can XVe chdiU() (https://man7.org/linux/man-pages/man2/chdir.2.html) Wo change iWV diUecWoU\. To
WeVW Whe implemenWaWion of Whe cd command in VmallVh, don'W XVe geWenY("PWD") becaXVe iW Zill noW giYe \oX
Whe coUUecW UeVXlW. InVWead, \oX can XVe Whe fXncWion geWcZd() (https://man7.org/linux/man-
pages/man3/getcwd.3.html) . HeUe iV Zh\ geWenY("PWD") doeVn'W giYe \oX Whe coUUecW UeVXlW:
PWD iV an enYiUonmenW YaUiable.
AV diVcXVVed in ModXle 4, E[ploUaWion: EnYiUonmenW "When a paUenW pUoceVV foUkV a child pUoceVV, Whe
child pUoceVV inheUiWV Whe enYiUonmenW of iWV paUenW pUoceVV."
When \oX UXn VmallVh fUom a baVh Vhell, VmallVh inheUiWV Whe enYiUonmenW of WhiV baVh Vhell
The YalXe of PWD in Whe baVh Vhell iV VeW Wo Whe diUecWoU\ in Zhich \oX aUe Zhen \oX UXn Whe command Wo
VWaUW VmallVh
VmallVh inheUiWV WhiV YalXe of PWD .
When \oX change Whe diUecWoU\ in VmallVh, iW doeVn'W XpdaWe Whe YalXe of Whe enYiUonmenW YaUiable PWD
Ɣĺ EŠec†ঞng O|heu Commandv
NoWe WhaW if e[ec() iV Wold Wo e[ecXWe VomeWhing WhaW iW cannoW do, like UXn a pUogUam WhaW doeVn'W e[iVW, iW Zill
fail, and UeWXUn Whe UeaVon Zh\. In WhiV caVe, \oXU Vhell VhoXld indicaWe Wo Whe XVeU WhaW a command coXld noW
be e[ecXWed (Zhich \oX knoZ becaXVe e[ec() UeWXUned an eUUoU), and VeW Whe YalXe UeWUieYed b\ Whe bXilW-in
VWaWXV command Wo 1.
Make VXUe WhaW Whe child pUoceVV WhaW haV had an e[ec() call fail WeUminaWeV iWVelf, oU elVe iW ofWen loopV back
Xp Wo Whe Wop and WUieV Wo become a paUenW Vhell. ThiV iV eaV\ Wo VpoW: if Whe oXWpXW of Whe gUading VcUipW VeemV
Wo be UepeaWing iWVelf, When \oX'Ye likel\ goW a child pUoceVV WhaW didn'W WeUminaWe afWeU a failed e[ec().
YoX can chooVe an\ fXncWion in Whe e[ec() famil\. HoZeYeU, Ze VXggeVW WhaW XVing eiWheU e[eclp() oU
e[ecYp() Zill be VimpleVW becaXVe of Whe folloZing UeaVonV
1. VmallVh doeVn'W need Wo paVV a neZ enYiUonmenW Wo Whe pUogUam. So Whe addiWional fXncWionaliW\ pUoYided
b\ Whe e[ec() fXncWionV ZiWh nameV ending in e iV noW UeTXiUed.
2. One e[ample of a command WhaW VmallVh needV Wo UXn iV lV (Whe gUadeUV Zill WU\ WhiV command aW Whe
VWaUW of Whe WeVWing). RXnning WhiV command Zill be a loW eaVieU XVing Whe e[ec() fXncWionV WhaW VeaUch Whe
PATH enYiUonmenW YaUiable.
ѵĺ Inr†| ş O†|r†| Rediuecঞon
We Uecommend WhaW Whe needed inpXW/oXWpXW UediUecWion VhoXld be done in Whe child pUoceVV.
NoWe WhaW afWeU XVing dXp2() Wo VeW Xp Whe UediUecWion, Whe UediUecWion V\mbol and UediUecWion
deVWinaWion/VoXUce aUe NOT paVVed inWo Whe e[ec command
FoU e[ample, if Whe command giYen iV lV > jXnk , When \oX handle Whe UediUecWion Wo "jXnk" ZiWh dXp2()
and When Vimpl\ paVV lV inWo e[ec() .
ƕĺ EŠec†ঞng Commandv in Foueguo†nd ş Backguo†nd
Foueguo†nd Commandv
FoU a foUegUoXnd command, iW iV Uecommend Wo haYe Whe paUenW Vimpl\ call ZaiWpid() on Whe child, Zhile iW
ZaiWV.
Backguo†nd Commandv
The Vhell VhoXld UeVpecW Whe inpXW and oXWpXW UediUecWion opeUaWoUV foU a command UegaUdleVV of ZheWheU Whe
command iV Wo be UXn in Whe foUegUoXnd oU Whe backgUoXnd.
ThiV meanV WhaW a backgUoXnd command VhoXld XVe /deY/nXll foU inpXW onl\ Zhen inpXW UediUecWion iV noW
Vpecified in Whe command.
SimilaUl\ a backgUoXnd command VhoXld XVe /deY/nXll foU oXWpXW onl\ Zhen oXWpXW UediUecWion iV noW
Vpecified in Whe command.
YoXU paUenW Vhell Zill need Wo peUiodicall\ check foU Whe backgUoXnd child pUoceVVeV Wo compleWe, Vo WhaW Whe\
can be cleaned Xp, aV Whe Vhell conWinXeV Wo UXn and pUoceVV commandV.
ConVideU VWoUing Whe PIDV of non-compleWed backgUoXnd pUoceVVeV in an aUUa\. Then eYeU\ Wime BEFORE
UeWXUning acceVV Wo Whe command line Wo Whe XVeU, \oX can check Whe VWaWXV of WheVe pUoceVVeV XVing
ZaiWpid(...NOHANG...) .
AlWeUnaWiYel\, \oX ma\ XVe a Vignal handleU Wo immediaWel\ ZaiW() foU child pUoceVVeV WhaW WeUminaWe, aV
oppoVed Wo peUiodicall\ checking a liVW of VWaUWed backgUoXnd pUoceVVeV
The Wime Wo pUinW oXW Zhen WheVe backgUoXnd pUoceVVeV haYe compleWed iV jXVW BEFORE command line
acceVV and conWUol aUe UeWXUned Wo Whe XVeU, eYeU\ Wime WhaW happenV.
Ѷĺ SignaѴv SIGINT ş SIGTSTP
ReenWUanc\ iV impoUWanW Zhen Ze conVideU WhaW Vignal handleUV caXVe jXmpV in e[ecXWion WhaW caXVe
pUoblemV ZiWh ceUWain fXncWionV. NoWe WhaW Whe pUinWf() famil\ of fXncWionV iV NOT UeenWUanW. In \oXU Vignal
handleUV, Zhen oXWpXWWing We[W, \oX mXVW XVe oWheU oXWpXW fXncWionV!
Wha| |o |†un inĵ
YoX can onl\ XVe C foU coding WhiV aVVignmenW and \oX mXVW XVe Whe gcc compileU.
YoX can XVe C99 oU GNU99 VWandaUd oU Whe defaXlW VWandaUd XVed b\ Whe gcc inVWallaWion on oV1.
YoXU aVVignmenW Zill be gUaded on oV1.
SXbmiW a Vingle ]ip file ZiWh all \oXU code, Zhich can be in aV man\ diffeUenW fileV aV \oX ZanW.
ThiV ]ip file mXVW be named \oXUonid_pUogUam3.]ip ZheUe \oXUonid VhoXld be Ueplaced b\ \oXU oZn
ONID.
E.g., if chaXdhUn ZaV VXbmiWWing Whe aVVignmenW, Whe file mXVW be named chaXdhUn_pUogUam3.]ip .
In Whe ]ip file, \oX mXVW inclXde a We[W file called README.W[W WhaW conWainV inVWUXcWionV on hoZ Wo compile
\oXU code XVing gcc Wo cUeaWe an e[ecXWable file WhaW mXVW be named VmallVh .
YoXU ]ip file VhoXld noW conWain an\ e[WUaneoXV fileV. In paUWicXlaU, make VXUe noW Wo ]ip Xp
Whe __MACOSX diUecWoUieV.
When \oX UeVXbmiW a file in CanYaV, CanYaV can aWWach a VXffi[ Wo Whe file, e.g., Whe file name ma\ become
chaXdhUn_pUogUam3-1.]ip . Don'W ZoUU\ aboXW WhiV name change aV no poinWV Zill be dedXcWed becaXVe of
WhiV.
Ca†ঞon
DXUing Whe deYelopmenW of WhiV pUogUam, Wake e[WUa caUe Wo onl\ do \oXU ZoUk on oV1, oXU claVV VeUYeU, aV
\oXU VofWZaUe Zill likel\ negaWiYel\ impacW ZhaWeYeU machine iW UXnV on, eVpeciall\ befoUe iW iV finiVhed. If \oX
caXVe WUoXble on one of Whe non-claVV, pXblic VeUYeUV, iW coXld hXUW \oXU gUade! If \oX aUe haYing WUoXble
logging in Wo an\ of oXU EECS VeUYeUV becaXVe of UXnaZa\ pUoceVVeV, pleaVe XVe WhiV page Wo kill off an\
pUogUamV UXnning on \oXU accoXnW WhaW mighW be blocking \oXU acceVV:
T.E.A.C.H. - The Engineering Accounts and Classes Homepage
(https://teach.engr.oregonstate.edu/teach.php?t\pe=kill_runawa\_processes)
Guading Cui|euia
ThiV aVVignmenW iV ZoUWh 20% of \oXU gUade and WheUe aUe 180 poinWV aYailable foU iW. 170 poinWV aUe aYailable
in Whe WeVW VcUipW, Zhile Whe final 10 poinWV Zill be baVed on \oXU VW\le, UeadabiliW\, and commenWing. CommenW
Zell, ofWen, and YeUboVel\: Ze ZanW Wo Vee WhaW \oX aUe Welling XV WHY \oX aUe doing WhingV, in addiWion Wo
Welling XV WHAT \oX aUe doing.
Once Whe pUogUam iV compiled, accoUding Wo \oXU VpecificaWionV giYen in README.W[W, \oXU Vhell Zill be
e[ecXWed Wo UXn a feZ Vample commandV againVW (lV, VWaWXV, e[iW, in WhaW oUdeU). If Whe pUogUam doeV noW
VXcceVVfXll\ ZoUk on WhoVe commandV, iW Zill UeceiYe a ]eUo. If iW ZoUkV, When Whe gUading VcUipW Zill be UXn
againVW iW (aV deWailed beloZ) foU final gUading. PoinWV Zill be aVVigned accoUding Wo Whe gUading VcUipW UXnning
on oXU claVV VeUYeU onl\.
Guading Me|hod
HeUe iV Whe gUading VcUipW p3testscript. IW iV a baVh VcUipW WhaW VWaUWV Whe VmallVh pUogUam and UXnV commandV
on VmallVh'V command line. MoVW of Whe commandV UXn b\ Whe gUading VcUipW aUe YeU\ VimilaU Wo Whe
ToWal PoinWV: 180.0
Assignment 2 Rubric
Criteria Ratings Pts
170.0 pWV
10.0 pWV
commandV VhoZn in Whe VecWion Sample PUogUam E[ecXWion. YoX can open Whe VcUipW in a We[W ediWoU. The
commenWV in Whe VcUipW Zill VhoZ \oX Whe poinWV foU indiYidXal iWemV. UVe Whe VcUipW Wo pUepaUe foU \oXU gUade,
aV WhiV iV hoZ iW'V being eaUned.
To UXn Whe VcUipW, place iW in Whe Vame diUecWoU\ aV \oXU compiled Vhell, chmod iW ( chmod +[ ./p3WeVWVcUipW )
and UXn WhiV command fUom a baVh pUompW:
$ ./p3WeVWVcUipW 2>&1
oU
$ ./p3WeVWVcUipW 2>&1 _ moUe
oU
$ ./p3WeVWVcUipW > m\WeVWUeVXlWV 2>&1
Do noW ZoUU\ if Whe Vpacing, indenWaWion, oU look of Whe oXWpXW of Whe VcUipW iV diffeUenW Whan Zhen \oX UXn iW
inWeUacWiYel\: WhaW Zon¶W affecW \oXU gUade. The VcUipW ma\ add e[WUa colonV aW Whe beginning of lineV oU do oWheU
ZeiUd WhingV, like pXW oXWpXW aboXW WeUminaWing pUoceVVeV fXUWheU doZn Whe VcUipW Whan \oX inWended.
If \oXU pUogUam doeV noW ZoUk ZiWh Whe gUading VcUipW, and \oX inVWead UeTXeVW WhaW Ze gUade \oXU VcUipW b\
hand, Ze Zill appl\ a 15% UedXcWion Wo \oXU final VcoUe. So fUom Whe YeU\ beginning, make VXUe WhaW \oX ZoUk
ZiWh Whe gUading VcUipW on oXU claVV VeUYeU!
PoinWs from Whe WesW scripW 170.0 pts
FXll Marks
0.0 pts
No Marks
The code is fXll\ commenWed 10.0 pts
FXll Marks
0.0 pts
No Marks

欢迎咨询51作业君
51作业君

Email:51zuoyejun

@gmail.com

添加客服微信: abby12468