-
Notifications
You must be signed in to change notification settings - Fork 0
/
subject.hy.txt
39 lines (30 loc) · 3.31 KB
/
subject.hy.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
Առաջադրանքի անունը՝ microshell
Ակնկալվող ֆայլեր՝ *.c *.h
Թույլատրված ֆունցկիաներ՝ malloc, free, write, close, fork, waitpid, signal, kill, exit, chdir, execve, dup, dup2, pipe, strcmp, strncmp
--------------------------------------------------------------------------------------
Գրել ծրագիր, որը կդրսևորի shell հրամանի պես վարք։
- Իրականացվելիք հրամանի տողը այս ծրագրի արգումենտը կլինի։
- Գործարկելի ծրագրերի ուղին կլինի բացարձակ կամ հարաբերական, բայց ձեր ծրագիրը չպետք է ուղի կառուցի (օրինակ՝ PATH-ի փոփոխականներով)։
- Պետք է իրականացնեք «|» և «;»՝ ինչպես bash-ի դեպքում։
- Մենք երբեք «|»-ը չենք գործածի, որը անմիջապես հաջորդված կամ նախորդված է ոչ մի բանով կամ «|»-ով կամ «;»-ով։
- Ձեր ծրագիրը պետք է իրականացնի ներկառուցված cd հրամանը՝ որպես արգումենտ գործածելով միայն ուղին (առանց «-»-ի կամ առանց պարամետրերի)։
- Եթե cd-ն սխալ քանակի արգումենտ ունի, ձեր ծրագիրը պետք է STDERR-ում տպի «error: cd: bad arguments», որից հետո՝ '\n'։
- Եթե cd-ն ձախողվի, ծրագիրը պետք է STDERR-ում տպի «error: cd: cannot change directory to path_to_change», որից հետո՝ '\n', որտեղ path_to_change-ը փոխարինված կլինի cd-ի արգումենտով։
- cd հրամանից անմիջապես հետո կամ առաջ երբեք «|» չի լինի։
- Դուք ոչ մի տեսակի դերանշանի (*, ~ և այլն...) հետ գործ չունեք։
- Դուք գործ չունեք միջավայրի փոփոխականների ($BLA ...) հետ։
- Եթե համակարգի կանչը, execve-ից ու chdir-ից բացի, սխալ վերադարձնի, ձեր ծրագիրը անմիջապես պետք է տպի «error: fatal» STDERR-ում, որից հետո՝ '\n', և ծրագիրը պետք է դուրս գա։
- Եթե execve-ը ձախողվի, պետք է տպեք «error: cannot execute executable_that_failed» STDERR-ում, որից հետո՝ «\n»․ executable_that_failed-ը պետք է փոխարինել ձախողված գործարկելիի ուղիով (այն պետք է execve-ի առաջին արգումենտը լինի)։
- Ձեր ծրագիրը պետք է կարողանա աշխատել ավելի քան հարյուրավոր «|»-երի հետ, նույնիկ եթե «open files»-երի քանակը սահմանափակենք՝ դարձնելով 30-ից քիչ։
Օրինակ սա կաշխատի՝
$>./microshell /bin/ls "|" /usr/bin/grep microshell ";" /bin/echo i love my microshell
microshell
i love my microshell
$>./microshell /bin/echo WOOT "; /bin/echo NOPE;" "; ;" ";" /bin/echo YEAH
WOOT ; /bin/echo NOPE; ; ;
YEAH
$>
Հուշում՝
Չմոռանաք միջավայրի փոփոխականը execve-ին փոխանցել
Հուշում՝
Ֆայլի նկարագրիչների արտահոսք չի թույլատրվում։