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”
分类:Linux
Linux, RHEL, CentOS, etc.
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.
glibc 的 malloc per thread arenas 特性
本文准确性有待深究,只查阅过部分资料和进行过一些简单讨论,并未在代码层面进行过研究。如有纠错或补充,请在本文留言,感谢!
从 RHEL5 迁移到 RHEL6 的用户会有这样的发现:多线程程序在 RHEL6 中占用的*虚拟内存*,要比在 RHEL5 上的多。这种情况在 JAVA 程序中尤为突出,尽管 JAVA 应用是单线程的。
其中的一个原因,是 glibc 2.12 中的新特性 malloc per thread arenas 造成的。
Java 占用较多虚拟内存
通常,Java 应用会运行在 JVM 上。JVM 有自己的一套内存调用方式,一般不会使用到 glibc. 但某些对象还是会调用 malloc,从而使用使用到 per thread arenas 这个特性。
为何有 per thread arenas?
在过去的 malloc 实现中,每个程序会有一个 main arenas 供 malloc 申请使用。对于多线程的程序,每个线程调用 malloc 的时候,都需要事先检查是否有锁,确认没有锁后,才能拿到内存空间。这影响了程序的性能。
在现在的实现中,每一个线程都会有自己的 arenas,这就避免了线程之间的竞争,从而提高性能。
另外,我们可以看到 arenas 是一些大约为 64MB 的无权限匿名页(64位系统中)。
继续阅读“glibc 的 malloc per thread arenas 特性”
Linux 中删除正在被进程占用的文件,磁盘空间不被释放。
在 Linux 系统中,通过 rm 命令删除一个文件,实际上是在相应的目录结构中 unlink 这个文件。如果这个文件仍然被打开着,这个文件仍然可以被这个进程所使用,并将继续占用磁盘空间。等这个程序关闭该文件后,对应文件的空间才会被释放。
=== TEST STEPS ===
继续阅读“Linux 中删除正在被进程占用的文件,磁盘空间不被释放。”