개요

Currently, process_exec() does not support passing arguments to new processes. Implement this functionality, by extending process_exec() so that instead of simply taking a program file name as its argument, it divides it into words at spaces. The first word is the program name, the second word is the first argument, and so on. That is, process_exec("grep foo bar") should run grep passing two arguments foo and bar.

Within a command line, multiple spaces are equivalent to a single space, so that process_exec("grep foo bar") is equivalent to our original example. You can impose a reasonable limit on the length of the command line arguments. For example, you could limit the arguments to those that will fit in a single page (4 kB). (There is an unrelated limit of 128 bytes on command-line arguments that the pintos utility can pass to the kernel.)

You can parse argument strings any way you like. If you're lost, look at strtok_r(), prototyped in include/lib/string.h and implemented with thorough comments in lib/string.c. You can find more about it by looking at the man page (run man strtok_r at the prompt).

목표

<aside> 💡 사용자 프로그램이 실행되기 전에, 커널은 무조건 해당 함수의 인자들을 스택에 저장해야 한다.

</aside>

커맨드 라인 파싱 기능 구현.

현재 핀토스는 커맨드 라인에 입력된 프로그램과 인자를 구분하지 못한다. 따라서 프로그램 이름과 인자를 구분하여 스택에 저장한 다음, 인자를 응용 프로그램에 전달하는 기능을 구현한다.

프로그램 실행 과정

Untitled

$pintos –q run 'echo x'

<aside> 💡 사용자 프로세스가 새로운 사용자 프로세스를 실행시킬 수도 있지만, 여기는 아예 최초로 커맨드 라인에서 받은 실행 파일을 실행시키는 것이므로 커널 스레드가 사용자 프로그램을 실행시킨다.

</aside>