Hi there!

I am a student studying computer science.

시스템 프로그래밍

시스템 프로그래밍 1장 - Shell, File system, Compile

만능성구 2020. 5. 5. 01:22
728x90

Shell이란?

User가 명령어 기반으로 운영체제에 쉽게 접근할 수 있도록 만들어준 interface!

(shall도 하나의 프로그래밍이다.)

Shell의 기능

- 다른 프로그램을 command line으로 실행한다.

- OS안의 file과 process를 command line으로 관리한다.

terminal에서 command를 치면 shell을 통해서 kernel, 즉 OS에 전달해서 기능을 한다.

주로 사용되는 Shell

기본적으로 여러가지 shell 프로그램이 설치가 되어있다.

shell관련된 utility들은

_ /bin / sh,

_ /bin / csh

_ /bin / tsch

_ /bin / ksh

_ /bin / bash #free ksh clone

Shell의 동작

계속 program을 실행시키다가 command나 typing을 하면 입력받은 명령어를 parsing(분석)해서 전달한다.

while (read command line from user) {
    parse the command line
    execute the command
}

terminal을 띄우면 while이 돌면서 받아드린다.

창을 안 띄워도 booting과 동시에 shell program은 실행된다.

어떤 터미널을 통해서든 계속 작업을 할 수 있게되어있다.

흔한 것은 interactive를 사용해서

  • Command history 명령어 기록
  • Command line editing 명령어 수정
  • File expansion (tab completion support) 특정 dir의 파일 을 볼 수 있다. tab을 눌러보면 알 수있다.
  • Command expansion 명령어를 입력하고 tab을 누르면 해당 되는 것을 알려준다.
  • Key bindings
  • Spelling correction
  • Job control

명령어란

shell 실행시키는 기본 단위

단어 or 여러 구문 (like 문장)

argument로 명령어의 속성을 알려준다.

z.B)

ls : 보여줘라

ls -l /bin : /bin에 있는 것 파일에 대한 상세정보 display

tar : 압축하라

tar -c -v -f archive.tar main.c main.h

(ververs여러 시퀀스 출력)

(cerate)

(file)

#c와 f가 합쳐져서

main.c와 main.h를 압축해서 archive.tar를 만든다.

주로 사용하는

  • pwd : 현재 자기가 속한 dir를 보여준다
  • cd : dir를 arg로 변경해라
  • cat : text파일의 내용 stdout으로(터미널에) display
  • chmod : 파일 속성을 변경
  • vi : textediter를 실행해서 편집
  • ls : 특정 or 현재 dir 파일을 나열해라
  • rm : 지워라
  • mv : 이름을 옮겨라, 바꿔라
  • cp : 복사해라 soruce, dest
  • touch : 입력된 arg를 이름으로 아무것도 없는거 만들어라
  • mkdir : dir 생성
  • rmdir : dir 지워라
  • more : 정보를 현재 터미널 창에 맞게 단위별로 보여줘라
  • od: binary file 출력
  • ln : file에 대한 link를 걸어서 해당 파일을 경우해서 실행해라 z.B.)window단축 아이콘
  • file : 해당 파일에 대한 속성을 출력해라 z.B.) i386, txt, binary
  • passwd : 현재 유저의 passward를 변경
  • split : 파일을 분활 해라

한줄로 manual pages보는 법

man [section number] [keyword]

man을 이용해서 keyword에 대한 정보를 알 수 있다.

section생략가능 , 기본적으로 첫번 째에서 가져온다.

Section number

1. Executable programs or shell commands

2. System calls

3. Library calls

4. Special files

5. File formats and conventions

6 Games

7. Miscellaneous

8. System administration command (보통 root 계정이사용)


Linux file system의 구조

- root를 기반으로한 tree구조로 되어있다. 모든 파일들은root부터 시작하는 경로를 가진다.

- 파일을 담을 수 있는 공간인 directory가 있다.

- root 아래에 directory가 연속적으로 존재한다.

기본 directory

  • bin : binary관련
  • boot : booting관련
  • etc : 환경설정
  • home : 리눅스를 사용하는 사용작 계정마다 별도의 공간을 만들어주고 각자의 계정이 관리
  • usr : libray, header file 개발 관련

home directory

  - 유저에게 하나의 dir할당
  - user가 login하면 자신의 dir에 존재한다.

File/Directory Path

- 절대 경로

    현재 어디있든 상관없는 주소

- 상대경로

    현재 사용자가 있는 주소에서 directory

    ./java 현재 위치의 java directory

    ../include 현재 directory의 부모 directory를 include directory로

    어떤 위치에서는 ~하면 home으로

    cd. 제자리

    cd .. 부모로

File Permission

- 모든 파일은 접근 권한이 있다.

- read / write / execute 에 대한 권한이 owner / group / others이 가진다.

- 'ls -l' command로 확인할 수 있다.

- 접근 권한 변경은 chmod로 한다.

 

chomd [permission] [filename]

[permission] : binary값으로 준다. ex)111 111 111_(2)

시스템 프로그래밍 절차

 

 

gcc/g++사용하여 컴파일    gcc : C compiler

g++ : C++ compiler

 

 

 

 

 

 

 

 

 

 

 

 

shell command환경, gnu환경에서 compiler 방법

 

$ gcc sample.c

a.out이라는 binary파일 생성

 

$ gcc sample.c -o sample

sample이라는 binary파일 생성 // 이름을 정해줄 수 있다.

 

두개이상의 파일을 할때는

$ gcc file1.c file2.c -o fileout

링크를 실행해서 만든다.

 

728x90