'2022/02/11'에 해당되는 글 3건

  1. 2022.02.11 linux cache clear
  2. 2022.02.11 go lang rest
  3. 2022.02.11 파일 존재유무 확인하기
Linux2022. 2. 11. 22:06

리눅스에서 이상하게 free 명령어에서 free 인 부분이 적게 나오는데

이럴때는 drop_caches를 강제로 하면 메모리가 돌아온다.

$ free -h
              total        used        free      shared  buff/cache   available
Mem:           7.7G        1.2G        5.8G        232M        757M        6.1G
스왑:        2.0G          0B        2.0G

# echo 3 > /proc/sys/vm/drop_caches

$ free -h
              total        used        free      shared  buff/cache   available
Mem:           7.7G        1.2G        5.9G        235M        667M        6.1G
스왑:        2.0G          0B        2.0G

 

리눅스 캐시의 종류를 좀 더 봐야 할 듯.

파일 시스템을 알아서 캐싱하는 느낌이었는데 2번 항목이 그런거였나?

1. Clear PageCache only.
# sync; echo 1 > /proc/sys/vm/drop_caches

2. Clear dentries and inodes.
# sync; echo 2 > /proc/sys/vm/drop_caches

3. Clear pagecache, dentries, and inodes.
# sync; echo 3 > /proc/sys/vm/drop_caches 

[링크 : https://www.tecmint.com/clear-ram-memory-cache-buffer-and-swap-space-on-linux/amp/]

[링크 : https://support.huaweicloud.com/intl/en-us/trouble-ecs/ecs_trouble_0336.html]

 

 

 

'Linux' 카테고리의 다른 글

dmesg log_buf_len  (0) 2022.06.29
bash set -e set -x  (0) 2022.06.22
sort 컬럼 별 정렬하기  (0) 2022.02.08
elementary os  (0) 2022.01.28
linux 터미널 pause, resume  (0) 2022.01.11
Posted by 구차니
Programming/golang2022. 2. 11. 19:38

node.js 처럼 go mod init 명령을 통해 모듈을 설치할 수 있는 것 같다.

 

go 1.10은 지원도 끊어졌고 해당 명령어 지원하지 않으니

g0 1.11은 가야 할 것 같다.

[링크 : https://stackoverflow.com/questions/60410729/unknown-subcommand-mod-error-while-running-go-mod-init]

 

아래껀 천천히 테스트 해봐야겠네..

(우분투 20.04로 가야하나...)

go mod init noah.io/ark/rest
$ vi main.go
package main

import (
"encoding/json"
"net/http"
)

var users = map[string]*User{}

type User struct {
Nickname string `json:"nickname"`
Email    string `json:"email"`
}

func main() {
http.HandleFunc("/users", func(wr http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet: // 조회
json.NewEncoder(wr).Encode(users) // 인코딩
case http.MethodPost: // 등록
var user User
json.NewDecoder(r.Body).Decode(&user) // 디코딩

users[user.Email] = &user

json.NewEncoder(wr).Encode(user) // 인코딩
}
})
http.ListenAndServe(":8080", nil)
}

[링크 : https://woony-sik.tistory.com/m/12]

 

$ go get github.com/julienschmidt/httprouter
$ vi rest.go
package main

import (
    "fmt"
    "github.com/julienschmidt/httprouter"
    "net/http"
    "log"
)

func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
    fmt.Fprint(w, "Welcome!\n")
}

func Hello(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
    fmt.Fprintf(w, "hello, %s!\n", ps.ByName("name"))
}

func main() {
    router := httprouter.New()
    router.GET("/", Index)
    router.GET("/hello/:name", Hello)

    log.Fatal(http.ListenAndServe(":8080", router))
}

[링크 : https://okky.kr/article/386116]

 

+

backport를 깔아주면 된다고는 한다.

$ sudo add-apt-repository ppa:longsleep/golang-backports
$ sudo apt-get install software-properties-common
$ sudo apt-get update 
$ sudo apt-get install golang-1.11

[링크 : https://www.gophp.io/install-go-1-11-on-ubuntu-18-04/]

 

추가해보니 1.18까지도 나왔나 보다.

$ sudo add-apt-repository ppa:longsleep/golang-backports
Golang 1.8, 1.9, 1.10, 1.11, 1.12, 1.13, 1.14, 1.15, 1.16, 1.17 and 1.18 PPA for Ubuntu
 더 많은 정보: https://launchpad.net/~longsleep/+archive/ubuntu/golang-backports
[ENTER]을 눌러 진행하거나 Ctrl-c를 눌러 추가하는것을 취소합니다.

 

그래도 1.17을 기준으로 설치 되는 듯.

$ sudo apt-get install golang
패키지 목록을 읽는 중입니다... 완료
의존성 트리를 만드는 중입니다
상태 정보를 읽는 중입니다... 완료
다음 패키지가 자동으로 설치되었지만 더 이상 필요하지 않습니다:
  golang-1.10-go golang-1.10-race-detector-runtime golang-1.10-src
  golang-1.11-doc golang-1.11-go golang-1.11-race-detector-runtime
  golang-1.11-src golang-race-detector-runtime
Use 'sudo apt autoremove' to remove them.
다음의 추가 패키지가 설치될 것입니다 :
  golang-1.17 golang-1.17-doc golang-1.17-go golang-1.17-src golang-doc
  golang-go golang-src
제안하는 패키지:
  bzr | brz mercurial subversion
다음 새 패키지를 설치할 것입니다:
  golang golang-1.17 golang-1.17-doc golang-1.17-go golang-1.17-src golang-doc
다음 패키지를 업그레이드할 것입니다:
  golang-go golang-src
2개 업그레이드, 6개 새로 설치, 0개 제거 및 1개 업그레이드 안 함.
72.0 M바이트 아카이브를 받아야 합니다.
이 작업 후 424 M바이트의 디스크 공간을 더 사용하게 됩니다.

'Programming > golang' 카테고리의 다른 글

golang gore(repl), delve  (0) 2022.03.31
go build 옵션  (0) 2022.03.31
go lang static http server  (0) 2022.03.10
go hello world build static / shared  (0) 2022.02.17
golang  (0) 2020.05.18
Posted by 구차니
Linux API/linux2022. 2. 11. 11:06

tmpfs에 touch로 파일을 생성/삭제하면서 테스트 해보니

마우스 이벤트에 묶여있어도 cpu 점유율 이 크게 오르지 않는걸 봐서는 부하가 크지 않은 듯.

 

if( access( fname, F_OK ) == 0 ) {
    // file exists
} else {
    // file doesn't exist
}

[링크 : https://stackoverflow.com/questions/230062/whats-the-best-way-to-check-if-a-file-exists-in-c]

 

#include <unistd.h>
int access(const char *pathname, int mode);

The mode specifies the accessibility check(s) to be performed, and is either the value F_OK, or a mask consisting of the bitwise OR of one or more of R_OK, W_OK, and X_OK. F_OK tests for the existence of the file. R_OK, W_OK, and X_OK test whether the file exists and grants read, write, and execute permissions, respectively.

[링크 : https://linux.die.net/man/2/access]

 

F_OK 파일 존재여부
R_OK 파일 read 퍼미션 여부
W_OK 파일 write 퍼미션 여부
X_OK 파일 execute 퍼미션 여부

'Linux API > linux' 카테고리의 다른 글

posix message queue  (0) 2022.09.21
zeroMQ  (0) 2022.09.20
select, poll, epoll  (0) 2021.11.02
Unhandled fault: external abort on non-linefetch  (0) 2021.05.25
Stopped (tty input)  (0) 2021.05.21
Posted by 구차니