2023.11.14 TIL
Code, Image source: The Linux Programming Interface, Michael Kerrisk
$ gdb
(gdb) help
단축 command
c
== continue
s
== stepi
$ gdb [program name]
(gdb) run
$ gdb -p [pid] # pid를 알고있는 경우
# Example
$ gdb copy
(gdb) run seek_io seek_io_new
step
next
stepi
, nexti
continue
, c
finish
break [location]
, b
delete
, disable
, enable
watch [expression]
x argv[0]
x/x
: hexadecimalx/i
: assemblyprint evaluates
p *((struct datatype *) 0x20000
display argc
info registers
info frame
list [location]
backtrace
, bt
info threads
info breakpoints
set follow-fork-mode child
show follow-fork-mode
gdb fork_whos_on_first -tui
sudo apt install -y cgdb
cgdb fork_whos_on_first
ddd --debugger
$ code .
tasks.json
신경xlaunch.json
getpid()
→ pid 얻는 system call우리가 보는 Memory
export SHELL=/bin/bash
printenv
setenv
getenv
fork()
tlpi-dist/procexec/t_fork.c
debugging해보기switch()
에서 -exec set follow-fork-mode child
case0
와 default
의 시작에서 b
parent
로도 해보기exit()
wait()
tlpi-dist/procexec/multi_wait.c
waitpid()
WIFEXITED(status)
WIFSIGNALED(status)
WIFSTOPPED(status)
tlpi-dist/procexec/print_wait_status.c
execve()
tlpi-dist/procexec/t_execve.c
exec()
와 execve()
의 차이점 - by ChatGPTThe exec()
and execve()
functions are both part of the family of functions in Unix-like operating systems that are used to replace the current process image with a new one. However, they have some differences in terms of how they handle the command and arguments.
exec()
Function:
exec()
function is a family of functions, such as execl()
, execle()
, execlp()
, execv()
, and execvp()
. Each variant of exec()
takes different arguments and provides different ways of specifying the command and arguments.exec()
functions take the command and its arguments as separate parameters in the function call.Example (execl()
):
#include <unistd.h>int main() {
execl("/bin/ls", "ls", "-l", (char *)NULL);
// If execl() returns, an error occurred
return 1;
}
execve()
Function:
execve()
function is more flexible and allows you to explicitly pass the command, an array of arguments, and the environment variables as separate parameters.Example (execve()
):
#include <unistd.h>int main() {
char *args[] = {"ls", "-l", NULL};
char *envp[] = {NULL};
execve("/bin/ls", args, envp);
// If execve() returns, an error occurred
return 1;
}
In summary, the primary difference lies in the way you pass the command and its arguments. The execve()
function provides more control by allowing you to explicitly pass the arrays of arguments and environment variables, while the exec()
functions take these as separate parameters in the function call. The choice between them depends on the specific requirements of your program.
filebrowser 설치
curl -fsSL https://raw.githubusercontent.com/filebrowser/get/master/get.sh | bash filebrowser -r /path/to/your/files
bash: filebrowser: No such file or directory
curl: (23) Failure writing output to destination
curl -fsSL https://raw.githubusercontent.com/filebrowser/get/master/get.sh | bash -s filebrowser -r /path/to/your/files
google chrome 설치
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo apt install ./google-chrome-stable_current_amd64.deb
아니 이것도 arm64에서 안된다고? 세상이 나를 억까한다
대체재가 이거라고 함. chrome이 이거 기반이라고 함.
sudo apt install chromium-browser
execl("/usr/bin/chromium-browser", "chromium-browser", "http://localhost:8282", NULL);
Process에게 event가 발생했음을 알림
Interrupt service routine과 동급…
control+C
→ SIGINT
생성, Signal interrupt
tlpi-dist/signals/ouch.c
ouch…Process 죽이기
kill -9 [pid]
→ process 무조건 죽임pkill [process name]
→ process 무조건 죽임SIGSEGV
받아서 직접 signal handler 등록 가능 → seg fault 원인을 로그로 저장 → 중요❗raise
pause
tlpi-dist/signals/nonreentrant.c
tlpi-dist/procexec/multi_SIGCHLD.c
wait()
을 호출하지 않을 경우tlpi-dist/procexec/make_zombie.c
setitimer()
, alarm()
ITIMER_REAL
ITIMER_VIRTUAL
ITIMER_PROF
setitimer
getitimer
argument로 pointer로 주소 전달
tlpi-dist/timers/real_timer.c
UNIX Timer의 문제점 개선
sleep
sleep()
nanosleep()
tlpi-dist/timers/ptmr_sigev_signal.c
fork
, exec
, exit
, wait
, kill
, getpid
4 thread memory map
→ Thread마다 stack이 따로 잡힌다
Memory map 보기
sudo cat /proc/[pid]/maps
int pthread_create(pthread_t *thrd, const [thread attribute] *attr, void *(*start)(void *), void *arg);
pthread_t
→ pid 자료형void pthread_exit(void *retval);
wait()
과 같은..int pthread_join(pthread_t thrd, void **setval);
int pthread_detach(pthread_t thrd);
(gdb) info thread
(gdb) thread [#]
→ 다른 thread로 바꿈, backtrace
(bt
) 도 확인하면서…tlpi-dist/threads/thread_cancel.c
#include <pthread.h>
int pthread_cancel(pthread_t thread);