Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
Add 'linux-command/' from commit '3902ba06096a96f88be478d3bbc261380e6…
Browse files Browse the repository at this point in the history
…a3c48'

git-subtree-dir: linux-command
git-subtree-mainline: 95b791c
git-subtree-split: 3902ba0
  • Loading branch information
Codejune committed Nov 24, 2021
2 parents 95b791c + 3902ba0 commit cca4edb
Show file tree
Hide file tree
Showing 12 changed files with 2,765 additions and 0 deletions.
62 changes: 62 additions & 0 deletions linux-command/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Execute files
mytop
mylscpu
myps

# Temporary files
.dependency
*.sh
*.txt

# Prerequisites
*.d

# Object files
*.o
*.ko
*.obj
*.elf

# Linker output
*.ilk
*.map
*.exp

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

# Debug files
*.dSYM/
*.su
*.idb
*.pdb

# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
69 changes: 69 additions & 0 deletions linux-command/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
.SUFFIXES: .c .o
.PHONY: dep all new clean

# Compiler
CC = gcc
# Compile option
# -c: Generate object file
# -W, -Wall: Print warning about all ambigous grammer
# -Wextra: Print warning out of -W, -Wall
# -O2: Optimization
# -g: Debugging, PLEASE DELETE AFTER PROJECT COMPLETE!
CFLAGS = -c -W -Wall -Wextra -g $(INC)

# Execute program file
MYTOP = mytop
MYPS = myps
MYLSCPU = mylscpu
# Source file
COMMON_SRCS = common.c
MYTOP_SRCS = mytop.c
MYPS_SRCS = myps.c
MYLSCPU_SRCS = mylscpu.c
SRCS = $(COMMON_SRCS) $(MYTOP_SRCS) $(MYPS_SRCS) $(MYLSCPU_SRCS)
# Object file
COMMON_OBJS = $(COMMON_SRCS:.c=.o)
MYTOP_OBJS = $(MYTOP_SRCS:.c=.o)
MYPS_OBJS = $(MYPS_SRCS:.c=.o)
MYLSCPU_OBJS = $(MYLSCPU_SRCS:.c=.o)
OBJS = $(MYTOP_OBJS) $(MYLSCPU_OBJS) $(MYPS_OBJS)
# Library file
LIBS = -lncurses
# Include path
INC =

# Execute file grneration
# $@ = TARGET
# $^ = DEPENDENCY
# make all: Make all execute file
all : $(OBJS)
$(CC) -o $(MYTOP) $(MYTOP_OBJS) $(LIBS)
$(CC) -o $(MYPS) $(MYPS_OBJS) $(LIBS)
$(CC) -o $(MYLSCPU) $(MYLSCPU_OBJS) $(LIBS)
$(MYTOP) : $(MYTOP_OBJS)
$(CC) -o $@ $^ $(LIBS)
$(MYPS) : $(MYPS_OBJS)
$(CC) -o $@ $^ $(LIBS)
$(MYLSCPU) : $(MYLSCPU_OBJS)
$(CC) -o $@ $^ $(LIBS)

# Object file generation
$(MYTOP_OBJS):
$(CC) $(CFLAGS) $(MYTOP_SRCS)
$(MYPS_OBJS):
$(CC) $(CFLAGS) $(MYPS_SRCS)
$(MYLSCPU_OBJS):
$(CC) $(CFLAGS) $(MYLSCPU_SRCS)

# make dep: Make dependency information file
dep:
$(CC) -M $(INC) $(SRCS) > .dependency

# make new: Re-generation
new:
$(MAKE) clean
$(MAKE) all

# make clean: Remove all generated file
clean:
rm *.o $(MYTOP) $(MYPS) $(MYLSCPU)
53 changes: 53 additions & 0 deletions linux-command/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Linux Command

리눅스 명령어인 top, ps, lscpu 명령어 구현

## 0. Quick start

``` bash
$ git clone https://github.com/codejune/c-linux-command.git
$ cd c-linux-command

# 일괄 빌드
$ make

# 개별 빌드
$ make mytop
$ ./mytop
```

## 1. Environment

### Software

- Ubuntu 20.04.3 LTS (x86_64)
- Linux Kernel 5.11.22

### Hardware

- VM Instance
- 4 Core 8 Thread
- 8 GB RAM
- 60 GB Storage

## 2. Requirement

### 조건

- system() or exec() 계열 함수를 사용하여 해당 명령어를 호출 금지
- mytop, myps 명령어는 리눅스 top, ps 명령어와 최대한 유사한 결과를 출력하게 구현
- mylscpu 명령어의 경우 필수 구현 항목은 CPU Vendor ID, CPU 모델명, CPU 속도, 캐쉬 크기(L1i, L1d, L2 캐쉬) 이며 그 외의 항목은 추가 option으로 취급

### 출력

- mytop

![mytop](./assets/mytop.png)

- myps

![myps](./assets/myps.png)

- mylscpu

![mylscpu](./assets/mylscpu.png)
Binary file added linux-command/assets/mylscpu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added linux-command/assets/myps.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added linux-command/assets/mytop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit cca4edb

Please sign in to comment.