하찮은 19학번 컴공대생
yoonbot's devlog

개발일지 🎮/Pintos (핀토스) ☠️

[프로젝트 #0] 핀토스 설치하기

yoonbot_code 2021. 9. 13. 14:56

**아래 글은 개인 우분투 환경에서 핀토스를 설치하는것이 아닌, 조교님이 관리하고 베푸해주신 터미널로 핀토스를 실행했다.** 

 

 

 

대학교 컴퓨터공학 과정을 들으면서 1학년때는 기본 씨언어 프로그래밍 및 이산수학, 2~3학년때는 자료구조 및 알고리즘들, 그리고 그 범위에 마춘 실험 과목들, 이제 3~4학년쯤되면 본인은 컴퓨터가 프로그램이 실행하면 무엇을 하는지 대충 조금이라도 알 것이다 (프로세서가 반복적으로 instruction/명령을 메모리에서 갖고 오고 명령어를 해독하고 그리고 명령을 실행한다). 예를들면, 컴퓨터가 반복적으로 두 수들을 더하고 메모리에 접속하고 컨디션을 확인하고 다른 함수로 점프하고 등등. 위와 같은 과정들을 초마다 몇 억씩 반복된다고 생각하면 된다.

 

 

 

 

 

 

 

3~4학년 쯤 되면 위와 같은 상황들을 대충 파악하고 대학교 과정에서는 운영체제라는 과목을 들게 될 것이다. 운영체제에서는 구체적인 구조, 커널 및 커널의 중요성과 운영체제의 구조에 끼치는 커넬의 역할 또한 조사한다. 이어서 쓰레드, 멀티 쓰레드, 가상화, 스케쥴링 및 프로세싱 대해서도 배운다. 따라서 운영체제의 구성과 구조를 이해하기 위해 우리 학교도 포함한 컴퓨터과정 전공 갖추는 전국 대학교들은 학생들한테 핀토스의 일부를 구현하게 시킨다 (진짜 겁나 힘들지만).

 

 

 

 

 

 

 

핀토스 파일을 다운 받고 배시 프로필 환경을 아래와 같이 터미널에서 설정해주면 된다.

root@ubuntu:~$ sudo wget http://www.stanford.edu/class/cs140/projects/pintos/pintos.tar.gz
root@ubuntu:~$ tar xzf pintos.tar.gz // pintos 다이렉토리가 따로 생성한다 
root@ubuntu:~$ cd /pintos/src/utils  // pintos 다이렉토리 내에 있는 utils 서브다이렉토리에 이동한다
root@ubuntu:~/pintos/src/utils$ sudo pwd
// 출력: /home/root/pintos/src/utils
root@ubuntu:~/pintos/src/utils$ sudo echo "export PATH="$PATH:/home/root/pintos/src/utils"" >> ~/.bashrc 
// bash 프로필 파일에다 위와 같은 핀토스 파일을 저장한 경로를 지정하지 않으면 핀토스 명령어들을 쓰지 못한다.
root@ubuntu:~/pintos/src/utils$ source ~/.bashrc

원래는 다른 블로그들 보면서 환경 설정들을 마저해야하는데 (예를들면 여러 서브다이렉토리들을 방문해 Makefile 및 Make.vars 수정하기) 하지만 우분투 현재 버전 20.04에 의해 stropts.h 파일이 설치가 안 되있음으로 여러 빌드 오류들이 뜨고 있다. stropts.h 파일을 touch 로 설치/추가 했는데도 I_PUSH 라는 변수가 설정이 안되있다느니 뭐... 추가 오류들이 떠서 요즘 최신 우분투에는 핀토스를 설치하기 어려운 거 같다 (아직도 내 개인 우분투 부팅에서 핀토스를 설치하고 싶으니, 이 문제를 해결한 사람은 댓글 달아주셨으면 감사하겠습니다). 그래서 그런지 조교님이 따로 환경설정해주신 후 우리에게 리눅스 서버들을 putty라는 윈도용 터미널 서버 프로그램으로 인해 베푸해주셨다. 우리야 감사했고 환경설정 따로 할 필요가 없이 바로 빌드를 실행 할 수 있었다.

root@ubuntu:~/pintos/src/utils$ make
... // 대충 빌드 실행 중
root@ubuntu:~/pintos/src/threads$ make
... // 대충 빌드 실행 중 

빌드가 마쳤으면 명령어 pintos -v -- -q run alarm-multiple 을 실행해보자. 아래와 같은 결과가 출력되면 성공적으로 핀토스 설치를 마친것이다.

root@ubuntu:~/pintos/src/threads$ pintos -v -- -q run alarm-multiple
Prototype mismatch: submain::SIGVTALRM () vs none at /root/pintos/src/utils/pintos line 935.
Constant subroutine SIGVTALRM redefined at /root/pintos/src/utils/pintos line 927.
qemu-system-1386 -hda /root/OKxAP1XfG9.dsk -m 4 -net none -nographic -monitor null
PiLo hda1
Loading........
Kernel command line: -q run alarm-multiple
Pintos booting with 4,088 kB RAM...
382 pages available in kernel pool.
382 pages available in user pool.
Calibrating timer... 419,020,800 loops/s.
Boot complete.
Executing 'alarm-multiple':
(alarm-multiple) begin
(alarm-multiple) Creating 5 threads to sleep 7 times each.
(alarm-multiple) Thread 0 sleeps 10 ticks each time,
(alarm-multiple) thread 1 sleeps 20 ticks each time, and so on.
(alarm-multiple) If successful, product of iteration count and
(alarm-multiple) sleep duration will appear in nondescending order.
(alarm-multiple) thread 0: duration=10, iteration=1, product=10
(alarm-multiple) thread 0: duration=10, iteration=2, product=20
(alarm-multiple) thread 1: duration=20, iteration=1, product=20
(alarm-multiple) thread 0: duration=10, iteration=3, product=30
... // 위와 같은 형식으로 계속 실행 ...
(alarm-multiple) thread 4: duration=50, iteration=6, product=300
(alarm-multiple) thread 4: duration=50, iteration=7, product=350
(alarm-multiple) end
----------------------------------------------------------------------------------------
Execution of 'alarm-multiple' complete.
Timer: 594 ticks
Thread: 0 idle ticks, 595 kernel ticks, 0 user ticks
Console: 2954 characters output
Keyboard: 0 keys pressed
Powering off...