Minishell

DaewoongJeon·2021년 6월 8일
0

42seoul Subject

목록 보기
6/8

Minishell

  • Summary: The objective of this project is for you to create a simple shell. Yes, your own little bash or zsh. You will learn a lot about processes and file descriptors.
    요약: 이번 과제의 목표는 간단한 shell(bash or zsh)을 만드는 당신을 위한 것입니다. 당신은 많은 프로세스들과 file descriptor들에 대해 배울 것입니다.

Instruction

  • The existence of shells is linked to the very existence of IT. At the time, all coders agreed that communicating with a computer using aligned 1/0 switches was seriously irritating. It was only logical that they came up with the idea to communicate with a computer using interactive lines of commands in a language somewhat close to english.
    쉘의 존재는 IT의 존재와 매우 밀접하게 연결되어 있습니다. 당시에 모든 코더들은 1과 0을 번갈아 사용하면서 컴퓨터와 소통하는 것이 매우 짜증나는 일이었음에 동의했습니다. 영어에 가까운 command line을 사용하여 컴퓨터와 소통한다는 아이디어를 떠올린 것은 논리적인 발상이었습니다.
  • With Minishell, you’ll be able to travel through time and come back to problems people faced when Windows didn’t exist.
    당신은 minishell과 함께 윈도우가 존재하기 이전에 사람들이 직면했던 문제를 다시 경험해볼 것입니다.

Command Instructions

  • Your project must be written in accordance with the Norm. If you have bonus files/functions, they are included in the norm check and you will receive a 0 if there is a norm error inside.
    당신의 프로젝트는 Norm에 맞춰서 작성되어야 합니다. 만약 당신이 보너스도 진행했다면, 보너스 부분도 역시 norm check에 포함되어야 합니다. 만약 norm error가 과제안에서 발생하였을 경우에 당신은 0점을 받을 것입니다.
  • Your functions should not quit unexpectedly (segmentation fault, bus error, double free, etc) apart from undefined behaviors. If this happens, your project will be considered non functional and will receive a 0 during the evaluation.
    당신의 함수는 비정상적인 행동이 발생했을 때 예상치 못한 종료(segmentation fault, bus error, double free, etc)가 있어서는 안됩니다.
  • All heap allocated memory space must be properly freed when necessary. No leaks will be tolerated.
    메모리로 할당했던 모든 힙은 필요할 때 알맞게 free되어야 합니다. 메모리 누수는 허용되지 않습니다.
  • If the subject requires it, you must submit a Makefile which will compile your source files to the required output with the flags -Wall, -Wextra and -Werror, and your Makefile must not relink.
    만약 과제가 필요로 한다면 당신은 소스파일들을 다음 flags(-Wall, -Wextra and -Werror)를 포함한 출력으로 컴파일하는 Makefile을 제출해야합니다. 그리고 당신의 Makefile은 relink가 되어서는 안됩니다.
  • Your Makefile must at least contain the rules $(NAME), all, clean, fclean and re.
    당신의 Makefile은 적어도 다음의 규칙($(NAME), all, clean, fclean and re)은 포함해야 합니다.
  • To turn in bonuses to your project, you must include a rule bonus to your Makefile, which will add all the various headers, librairies or functions that are forbidden on the main part of the project. Bonuses must be in a different file _bonus.{c/h}. Mandatory and bonus part evaluation is done separately
    보너스 파트를 제출하기 위해서 당신은 Makefile에 bonus 규칙을 포함해야 합니다. bonus규칙이 포함되면 과제의 메인 파트에서 금지되었던 함수나 라이브러리, 다양한 헤더들이 추가될 것입니다. bonuses는 _bonus.{c/h}형태로서 다른 파일이어야 합니다. 필수파트와 보너스파트의 평가는 별개로 실행됩니다.
  • If your project allows you to use your libft, you must copy its sources and its associated Makefile in a libft folder with its associated Makefile. Your project’s Makefile must compile the library by using its Makefile, then compile the project.
    만약 당신의 프로젝트가 당신의 libft를 사용한다면 당신은 libft 소스들과 libft 디렉토리안의 Makefile을 minishell의 Makefile에 Copy해야 합니다. minishell의 Makefile은 libft Makefile을 사용하여 라이브러리를 컴파일 한 다음 libft 프로젝트를 컴파일해야합니다.
  • We encourage you to create test programs for your project even though this work won’t have to be submitted and won’t be graded. It will give you a chance to easily test your work and your peers’ work. You will find those tests especially useful during your defence. Indeed, during defence, you are free to use your tests and/or the tests of the peer you are evaluating.
    test program이 제출되지 않고 평가되지 않아도 우리는 당신의 프로젝트를 위해 test program을 만들어 볼 것을 추천합니다. 그것은 당신의 작업물과 협업물을 쉽게 test볼 수 있는 기회를 줄 것입니다. 만들어진 test는 defence동안 특히 유용합니다.
  • Submit your work to your assigned git repository. Only the work in the git repository will be graded. If Deepthought is assigned to grade your work, it will be done after your peer-evaluations. If an error happens in any section of your work during Deepthought’s grading, the evaluation will stop
    당신의 작업물을 할당된 깃 저장소에 제출하세요. 오직 깃 저장소 안에 있는 작업물 만이 평가됩니다. 만약 deepthought가 당신의 작업물을 평가할 경우, 그것은 피어평가 이후에 수행됩니다. 만약 deepthought에 의해 너의 작업물에서 error가 발견될 경우 평가는 중지됩니다.

Mandatory part

  • program name : minishell
  • Makefile : yes
  • External functions : readline, rl_on_new_line, rl_replace_line, rl_redisplay, add_history, printf, malloc, free, write, open, read, close, fork, wait, waitpid, wait3, wait4, signal, kill, exit, getcwd, chdir, stat, lstat, fstat, execve, dup, dup2, pipe, opendir, readdir, closedir, strerror, errno, isatty, ttyname, ttyslot, ioctl, getenv, tcsetattr, tcgetattr, tgetent, tgetflag, tgetnum, tgetstr, tgoto, tputs
  • Libft authorized : yes
  • Description : write a shell

Your shell should:

  • Not interpret unclosed quotes or unspecified special characters like \ or;
    기호로 닫혀있지 않거나 \나 ;같은 특정하지 않은 특수문자는 처리하면 안됩니다.
  • Not use more than one global variable, think about it and be ready to explain why you do it.
    전역변수는 하나만 사용할 수 있고, 전역변수를 썼을 때 왜 썼는지 설명할 수 있어야 합니다.
  • Show a prompt when waiting for a new command.
    새로운 명령어를 기다릴 때 프롬프트를 보여야 합니다.
    프롬프트 : 컴퓨터 터미널의 CLI(커맨드 라인 인터페이스)의 명령줄 대기모드를 가리킵니다.(ex. 사용자 @ 호스트이름 : (작업 중인)디렉토리전체경로명 $)
  • Have a working History.
    ???
  • Search and launch the right executable (based on the PATH variable or by using relative or absolute path)
    올바른 실행파일을 검색하고 시작하세요.(PATH 변수 기반이거나, 상대경로 또는 절대경로를 사용)
  • It must implement the builtins:
    다음의 내장기능을 구현해야 합니다.
  1. echo with option -n
  2. cd with only a relative or absolute path
  3. pwd with no options
  4. export with no options
  5. unset with no options
    변수 해제
  6. env with no options or arguments
    전역변수 조회(옵션이 추가되면 설정까지 가능)
  7. exit with no options
  • ’ inhibit all interpretation of a sequence of characters.
    '문자열의 처리를 금지합니다.
  • " inhibit all interpretation of a sequence of characters except for $.
    $을 제외하고 "문자열의 처리를 금지합니다.
  • Redirections:
    https://mug896.github.io/bash-shell/redirections.html
  1. < should redirect input.
    < 는 input으로 redirect 합니다.
  2. > should redirect output.
    >는 output으로 redirect 합니다.
  3. “<<” read input from the current source until a line containing only the de- limiter is seen. it doesn’t need to update history!
    "<<"는 구분 기호 만 포함 된 행이 표시 될 때까지 현재 소스에서 입력을 읽습니다. 기록을 업데이트 할 필요가 없습니다.
  4. “>>” should redirect output with append mode.
    ">>"는 추가 모드로 출력을 리디렉션해야합니다.
  • Pipes | The output of each command in the pipeline is connected via a pipe to the input of the next command.
    pipe안에서 각 명령어의 출력은 pipe를 통해 다음 명령어의 입력으로 연결됩니다.
  • Environment variables ($ followed by characters) should expand to their values.
    환경변수들($뒤에 오는 문자들)은 변수들의 값을 가리켜야 합니다.
  • $? should expands to the exit status of the most recently executed foreground pipeline.
    $?는 가장 최근 실행된 foreground pipeline의 종료상태를 가리킵니다.
  • ctrl-C ctrl-D ctrl-\ should work like in bash.
    ctrl-C ctrl-D ctrl-\는 bash에서처럼 동작해야 합니다.
  • When interactive:
    사용자와의 상호작용:
  1. ctrl-C print a new prompt on a newline.
    ctrl-C는 개행문자로 새로운 프롬프트를 표시해야 합니다.
  2. ctrl-D exit the shell.
    ctrl-D는 shell을 끝내야 합니다.
  3. ctrl-\ do nothing.
    ctrl-\는 아무것도 안합니다.
  • Anything not asked is not required.
    요청하지 않은 것은 필요하지 않습니다.
  • For every point, if you have any doubt take bash as a reference.
    모든 포인트에 대해서 의구심이 드는 부분은 bash를 참고서로 쓰세요.

허용 함수 설명

1. readline

https://man7.org/linux/man-pages/man3/readline.3.html

2. rl_on_new_line

3. rl_replace_line

4. rl_redisplay

5. add_history

6. printf

7. malloc

8. free

9. write

10. open

11. read

12. close

13. fork

  1. header
    #include <unistd.h>
  2. format
    pid_t fork(void);
  3. description
    새로운 자식 프로세스를 생성합니다.
  4. return value
  • 성공일 경우, 자식프로세스에게 0, 부모프로세스에게 자식프로세스의 ID를 return 합니다.
  • 실패일 경우, 부모프로세스에게 -1을 return 하고, 자식 프로세스가 생성되지 않는다. errno가 설정됩니다.

14~17. wait, waitpid, wait3, wait4

18. signal

19. kill

20. exit

21. getcwd

22. chdir

23~25. stat, lstat, fstat

27. execve

28~29. dup, dup2

30. pipe

31~33. opendir, readdir, closedir

34. strerror

35. errno

36. isatty

37. ttyname

38. ttyslot

39. ioctl

40. getenv

41. tcsetattr

42. tcgetattr

43~48. tgetent, tgetflag, tgetnum, tgetstr, tgoto, tputs

https://nxmnpg.lemoda.net/ko/3/tgetent

참고

1개의 댓글

comment-user-thumbnail
2021년 6월 14일

ttyslot 설명해주세요

답글 달기