Coder Social home page Coder Social logo

myshell's Introduction

myshell

리다이랙션과 파이프 기능을 포함한 쉘 프로그램


pipe

image

‘|’ 로 구분된 블록단위로 수행하고, 매 수행시 자식 프로세스를 하나 만들어서 수행하도록. 그리고 파이프를 둬서 본인 프로세스는 stdin을 파이프에서 입력받고 자식 프로세스(두 번째 이후로 만들어지는 경우 파이프에서 입력)는 stdout을 파이프로 출력하도록 해서 이전 블록이 다음 블록의 입력이 되도록 구현.

image

|’로 나뉜 블록들은 다음 함수에서 처리함. execvp수행 전 리다이랙션을 고려해준다.

image


redirection

image

‘|’로 나뉜 블록들을 하나씩 처리. 이 작은 블록은 ‘>’와 ‘<’으로 나뉜다. ‘>’, ‘<’ 이후엔 파일이름이 온다. ‘>’ 다음 파일은 출력을 할 파일이 되고, ‘<’ 다음 파일은 프로세스가 입력을 받을 파일이 된다. strtok으로 파싱.

image

기본적인 명령어 수행

image

execvp로 명령어 인자들을 전달해서 환경변수 위에 있는 기본 명령어를 수행.

void execute_cmd(char * cmd){
	char * cmd_vector[MAX_CMD_ARG];

	//make redirection
	redirection_maker(cmd);

	makelist(cmd, " \t", cmd_vector, MAX_CMD_ARG);
	
	execvp(cmd_vector[0], cmd_vector);
}

myshell's People

Contributors

lsn1106 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.