This is a very simple and buggy TCP socket example in Linux C. For demo only.
继续阅读“A simple TCP socket server example”
Note: The parent of a multi-process program could exit even if it has a D-state child
With default signal handling, I observe that when a child process keeps in D-state, I can terminate it parent process, and then the D-state child process would become a child of init (pid-1).
继续阅读“Note: The parent of a multi-process program could exit even if it has a D-state child”
Note: init not cleaning zombie process if it contains D-state thread(s)
I observed that when terminating a process with D-state thread(s), the process would keep in zombie state, instead of being reclaimed by init (pid-1). Here comes the steps to reproduce this behavior.
继续阅读“Note: init not cleaning zombie process if it contains D-state thread(s)”
How Linux measure CPU utilization with Hyper-Threading enabled?
There's no explicit definition of CPU utilization. Usually, we see CPU time as CPU utilization. The %id, %us, %sy etc seen in vmstat/iostat are CPU time.
~~~
CPU
These are percentages of total CPU time.
us: Time spent running non-kernel code. (user time, including nice time)
sy: Time spent running kernel code. (system time)
id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time.
wa: Time spent waiting for IO. Prior to Linux 2.5.41, included in idle.
st: Time stolen from a virtual machine. Prior to Linux 2.6.11, unknown.
~~~
继续阅读“How Linux measure CPU utilization with Hyper-Threading enabled?”
为什么 /proc/sys/vm/drop_caches 的值不归零?
首先,在 Linux 下清理缓存是毫无意义的,只有弊,没有利。原因可参考下文。
[Linux ate my ram!]
http://www.linuxatemyram.com/
继续阅读“为什么 /proc/sys/vm/drop_caches 的值不归零?”
Linux 下创建简单的守护进程(Daemon)
守护进程运行在背景,其父进程 pid=1(init/systemd). 创建守护进程的主要思路,就是 fork 一个子进程,然后父进程挂掉让子进程变为孤儿,最终孤儿被 pid=1 的进程领养。
Daemon 的创建步骤 (SysV)
1. Fork
fork off the parent process & let it terminate if forking was successful. -> Because the parent process has terminated, the child process now runs in the background.
2. Setsid
setsid - Create a new session. The calling process becomes the leader of the new session and the process group leader of the new process group. The process is now detached from its controlling terminal (CTTY).
3. Signal
Catch signals - Ignore and/or handle signals.
4. Fork again
fork again & let the parent process terminate to ensure that you get rid of the session leading process. (Only session leaders may get a TTY again.)
5. chdir
chdir - Change the working directory of the daemon.
6. umask
umask - Change the file mode mask according to the needs of the daemon.
7. Close FDs
close - Close all open file descriptors that may be inherited from the parent process.
吉隆坡第二国际机场(KLIA2)吃喝购物简介
KLIA2 是个友好的廉航机场,连接着 KLIA2 的商场 Gateway@KLIA2 卖的东西跟市区一个价,可选择的还不少。可惜没有电影院。
继续阅读“吉隆坡第二国际机场(KLIA2)吃喝购物简介”