who command
목적 : 현재 로그인 되어 있는 유저 정보를 모두 출력하기
output : user name, terminal, time, from where
whoami를 사용하여 볼 수 있다.
who command를 어떻게 사용할까?
→manual을 참조해라!
man who
여기서 알수있는 사실 : who는 /var/run/utmp에서 파일을 불러온다
man 명령어는 여러가지 specific sections이 있고, 이걸 사용해야 작동한다.
1 general commands
| 2 | system calls |
| 3 | C library functions |
| 4 | Special files |
| 5 | File formats and conventions |
| 6 | games |
| 7 | miscellaneous |
| 8 | sys admin commands and daemons |
- (1) 사용자 명령어 → ls, grep, who 같은 일반적인 명령어
- (2) 시스템 콜 → open(), read(), write() 같은 커널 제공 함수
- (3) 라이브러리 함수 → printf(), malloc() 같은 C 라이브러리 함수
- (4) 특수 파일 → /dev/null, /dev/tty 같은 디바이스 파일
- (5) 설정 파일 → /etc/passwd, /etc/fstab 같은 설정 파일 형식
- (6) 게임 및 오락 → fortune, rogue 같은 게임 관련 문서
- (7) 기타 → 매크로 패키지, 프로토콜, 표준 등 (man 7 signal)
- (8) 관리자 명령어 → mount, fdisk, iptables 같은 root 전용 명령어
man -k는 특정 키워드를 포함하는 매뉴얼 페이지를 검색하는 명령어입니다.
man -k utmp
less /usr/include/utmp.h 에서 내용을 확인하자.
who가 작동되는 과정
1 /var/run/utmp를 열기
| 2 | utmp structure 읽어오기 |
| 3 | display record |
| 4 | 2번단계로 돌아가기 |
| 5 | utmp 닫기 |
우리가 해야될일
- read structs from file(/var/run/utmp)
- 어떻게? → getc(), fgets() 문자나 줄을 읽는법을 알아야함.
- display the information stored in struct
따라서 system call으로 utmp를 불러온다.
printf같은건 c언어 함수고, systemcall은 open, read 등등이다.
int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode);
플래그 설명
O_RDONLY 읽기 전용(Open Read-Only)
| O_WRONLY | 쓰기 전용(Open Write-Only) |
| O_RDWR | 읽기/쓰기(Open Read-Write) |
| O_CREAT | 파일이 없으면 생성(Create) |
| O_EXCL | O_CREAT와 함께 사용 시, 파일이 이미 존재하면 실패(Exclusive) |
| O_TRUNC | 기존 파일 내용을 지움(Truncate) |
'SW > System Programming' 카테고리의 다른 글
| System Call (0) | 2025.03.30 |
|---|---|
| ls 명령어 (0) | 2025.03.30 |
| Linux 커널 (0) | 2025.03.30 |