examples里server.c涉及知识点 - mayunxi/st-study GitHub Wiki
1. Getopt()函数简单使用
https://mayunxi.github.io/2019/06/getopt()%E5%87%BD%E6%95%B0%E7%AE%80%E5%8D%95%E4%BD%BF%E7%94%A8/
2. sysconf(_SC_NPROCESSORS_ONLN)获取cpu核心数
3. Linux进程模型——回话和进程组(创建daemon(守护进程)进程)
https://www.jianshu.com/p/d953cac76de9
4. pid=1 :init进程,系统启动的第一个用户级进程,是所有其它进程的父进程,引导用户空间服务。
5. ./server进程情况
stfz@stfz-desktop:~/myworkspace/github/st-study/obj$ ps -axjf
PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND
1552 16425 16424 16424 ? -1 S 1000 0:00 \_ ./server -l
16425 16426 16424 16424 ? -1 S 1000 0:00 \_ ./serve
16425 16427 16424 16424 ? -1 S 1000 0:00 \_ ./serve
16425 16428 16424 16424 ? -1 S 1000 0:00 \_ ./serve
16425 16429 16424 16424 ? -1 S 1000 0:00 \_ ./serve
6. 进程间通信-信号
kill函数说明 kill()函数同咱们的kill系统命令一样(但不能误以为kill()就是kill哈),可以发送信号给进程或进程组(实际上,kill系统命令只是kill()函数的一个用户接口)。这里需要注意的是,kill()函数不仅可以终止进程(实际上是通过发出SIGKILL信号终止),也可以向进程发送其他信号。
查看信号:
stfz@stfz-desktop:~$ kill -l
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP
6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1
11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM
16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP
21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ
26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR
31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3
38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8
43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7
58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2
63) SIGRTMAX-1 64) SIGRTMAX
stfz@stfz-desktop:~/myworkspace/github/st-study/obj$ ps -ef |grep ./server
stfz 6998 1552 0 11:53 ? 00:00:00 ./server -l ../logs
stfz 6999 6998 0 11:53 ? 00:00:00 ./server -l ../logs
stfz 7000 6998 0 11:53 ? 00:00:00 ./server -l ../logs
stfz 7001 6998 0 11:53 ? 00:00:00 ./server -l ../logs
stfz 7002 6998 0 11:53 ? 00:00:00 ./server -l ../logs
stfz@stfz-desktop:~/myworkspace/github/st-study/obj$ kill -10 6998
Process #0 (pid 6999):
Listening Socket #0:
-------------------------
Address 0.0.0.0:8000
Thread limits (min/max) 8/512
Waiting threads 8
Busy threads 0
Requests served 0
Process #1 (pid 7000):
Listening Socket #0:
-------------------------
Address 0.0.0.0:8000
Thread limits (min/max) 8/512
Waiting threads 8
Busy threads 0
Requests served 0
Process #3 (pid 7002):
Listening Socket #0:
-------------------------
Address 0.0.0.0:8000
Thread limits (min/max) 8/512
Waiting threads 8
Busy threads 0
Requests served 0
Process #2 (pid 7001):
Listening Socket #0:
-------------------------
Address 0.0.0.0:8000
Thread limits (min/max) 8/512
Waiting threads 8
Busy threads 0
Requests served 0
stfz@stfz-desktop:~/myworkspace/g
stfz@stfz-desktop:~/myworkspace/github/st-study/obj$ kill -1 6998
[12/Jun/2019:12:01:11] INFO: watchdog: caught SIGHUP
[12/Jun/2019:12:01:11] INFO: process 2 (pid 7001): caught SIGHUP, reloading configuration
[12/Jun/2019:12:01:11] INFO: process 2 (pid 7001): configuration loaded
[12/Jun/2019:12:01:11] INFO: process 0 (pid 6999): caught SIGHUP, reloading configuration
[12/Jun/2019:12:01:11] INFO: process 0 (pid 6999): configuration loaded
[12/Jun/2019:12:01:11] INFO: process 1 (pid 7000): caught SIGHUP, reloading configuration
[12/Jun/2019:12:01:11] INFO: process 1 (pid 7000): configuration loaded
[12/Jun/2019:12:01:11] INFO: process 3 (pid 7002): caught SIGHUP, reloading configuration
[12/Jun/2019:12:01:11] INFO: process 3 (pid 7002): configuration loaded
stfz@stfz-desktop:~/myworkspace/github/st-study/obj$ kill -15 6998
[12/Jun/2019:14:43:44] INFO: watchdog: caught SIGTERM, terminating
[12/Jun/2019:14:43:44] INFO: process 3 (pid 7002): caught SIGTERM, terminating
[12/Jun/2019:14:43:44] INFO: process 1 (pid 7000): caught SIGTERM, terminating
[12/Jun/2019:14:43:44] INFO: process 0 (pid 6999): caught SIGTERM, terminating
[12/Jun/2019:14:43:44] INFO: process 2 (pid 7001): caught SIGTERM, terminating