The background of my question is a set of test cases for my Linux-kernel Namespaces discovery Go package lxkns where I create a new child user namespace as well as a new child PID namespace inside a test container. I then need to remount /proc, otherwise I would see the wrong process information and cannot lo…
Tag: procfs
How do I expose custom files similar to /procfs on Linux?
I have a writer process which outputs its status at regular intervals as a readable chunck of wchar_t. I would need to ensure the following properties: When there’s and update, the readers shouldn’t read partial/corrupted data The file should be volatile in memory so that when the writer quits, th…
How to avoid double creating directories in /proc?
I’m writing a Linux kernel module, and I’d like to create a subdirectory, /proc/foo/, and then expose several artificial files inside it that will be generated on the fly by my module. I know I can use proc_mkdir to create the foo directory, but if it already exists dmesg will display a warning, a…
can /proc/self/exe be mmap’ed?
Can a process read /proc/self/exe using mmap? This program fails to mmap the file: Answer You are making 2 mistakes here: Mapped size must be > 0. Zero-size mappings are invalid. You have to specify, if you want to create a shared (MAP_SHARED) or a private (MAP_PRIVATE) mapping. The following should work f…
Linux kernel: get information of page cache distribution over NUMA nodes
When Linux kernel runs on NUMA, each NUMA node has partially separate memory management. There is echo ‘?’ > /proc/sysrq-trigger function “Will dump current memory info to your console.” of SysRq (implemented as sysrq_handle_showmem and show_mem) to get basic memory statistics for e…
How does the kernel handle a read operation on proc files when several instances of the same driver are running simultaneously
I have a question regarding the way proc files are handled when several instances of the same driver are running simultaneously. lets assume that a my system runs a couple of instances of the same driver simultaneously, but only one of them (according to some inner decision making) created a proc file and mai…
Linux /proc/pid/smaps proportional swap (like Pss but for swap)
It seems (from looking at the Linux kernel source) that the Swap: metric in /proc/pid/smaps is the total swap accessible by the given pid. In the case where there is shared memory involved, this seems to be an over-approximation of actual swap usage. For example when summing swap usage of a parent pid with it…
thread level memory consumption of process
How do I get per thread based memory consumption of a process in Linux? I understand that we can use /proc/pid/task/tid/statm, but thats not helping my case. All the threads show same value and its same as PID’s statm. We can do valgrind but I am not looking for any invalid read/write or leaks. Valgrind…