procfs

Get local network interface addresses using only proc?

给你一囗甜甜゛ 提交于 2019-12-17 15:40:03
问题 How can I obtain the (IPv4) addresses for all network interfaces using only proc? After some extensive investigation I've discovered the following: ifconfig makes use of SIOCGIFADDR , which requires open sockets and advance knowledge of all the interface names. It also isn't documented in any manual pages on Linux. proc contains /proc/net/dev , but this is a list of interface statistics. proc contains /proc/net/if_inet6 , which is exactly what I need but for IPv6. Generally interfaces are

Get list of open files (descriptors) in OS X

ⅰ亾dé卋堺 提交于 2019-12-17 15:39:44
问题 I would like to get a list of open files in a process on os x (10.9.1). In Linux I was able to get this from /proc/PID/fd . However I'm not sure how to get the same on OS X. I found that the procfs is not present on the OS X (by default. possible implementations present, but I do not want to go that way). So how do I get (natively) the list of open files in a process on OS X. One way is lsof . is there any other support available? please let me know where I can get more info on this. Thanks.

sscanf in Python

不打扰是莪最后的温柔 提交于 2019-12-17 03:04:32
问题 I'm looking for an equivalent to sscanf() in Python. I want to parse /proc/net/* files, in C I could do something like this: int matches = sscanf( buffer, "%*d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %*X %*X:%*X %*X:%*X %*X %*d %*d %ld %*512s\n", local_addr, &local_port, rem_addr, &rem_port, &inode); I thought at first to use str.split , however it doesn't split on the given characters, but the sep string as a whole: >>> lines = open("/proc/net/dev").readlines() >>> for l in lines[2:]: >>> cols

sscanf in Python

拜拜、爱过 提交于 2019-12-17 03:04:18
问题 I'm looking for an equivalent to sscanf() in Python. I want to parse /proc/net/* files, in C I could do something like this: int matches = sscanf( buffer, "%*d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %*X %*X:%*X %*X:%*X %*X %*d %*d %ld %*512s\n", local_addr, &local_port, rem_addr, &rem_port, &inode); I thought at first to use str.split , however it doesn't split on the given characters, but the sep string as a whole: >>> lines = open("/proc/net/dev").readlines() >>> for l in lines[2:]: >>> cols

copy_from_user warning on size not being provably correct?

試著忘記壹切 提交于 2019-12-11 11:06:53
问题 I encountered a warning produced when compiling my kernel module that I can't get to work around. First take a look at this simplified code: #define READ_CHUNK 100u static int _procfs_write(struct file *file, const char *buf, unsigned long count, void *data) { char command[READ_CHUNK]; unsigned long left = count; while (left > 0) { unsigned int amount = left<READ_CHUNK?left:READ_CHUNK; if (copy_from_user(command, buf, amount)) return -EFAULT; buf += amount; left -= amount; /* process buffer *

Programmatically drop Linux cache as non-root user

夙愿已清 提交于 2019-12-10 14:44:20
问题 For testing purposes, I can drop cached memory by writing to the drop_caches file in Linux under the procfs. I can only do this as root. This is on embedded Linux so there is no sudo. sync; echo 3 > /proc/sys/vm/drop_caches I can write to the file programmatically in c++ by doing something from the post --> How to programmatically clear the filesystem memory cache in C++ on a Linux system? sync(); std::ofstream ofs("/proc/sys/vm/drop_caches"); ofs << "3" << std::endl; The challenge is wanting

Create ProcFS entry in /proc/net

允我心安 提交于 2019-12-10 11:19:27
问题 I try to create an entry inside /proc/net from a kernel module, like this: struct file *filp = filp_open("/proc/net", O_RDONLY, 0); struct proc_dir_entry *parent = PDE(filp->f_dentry->d_inode); filp_close(filp, NULL); proc_file = create_proc_entry("test", 0644, parent); Crudely taken from here Why does it create my entry like /proc/test instead of /proc/net/test ? (Note: I'd like too use create_proc_entry , not proc_create .) 回答1: In recent kernels you won't find create_proc_entry() anymore,

What is the maximum allowed limit on the length of a process name?

徘徊边缘 提交于 2019-12-10 03:34:32
问题 What is the maximum length allowed for a process name? I am reading the process name from /proc/[pid]/stat file and i would like to know the maximum buffer that i would need. I am pretty sure there is a limit which is configurable but just can't find out where this is. 回答1: According to man 2 prctl: PR_SET_NAME (since Linux 2.6.9) Set the name of the calling thread, using the value in the location pointed to by (char *) arg2. The name can be up to 16 bytes long , and should be null-terminated

why proc/ID/maps has multiple entries for shared libraries

我的梦境 提交于 2019-12-08 03:00:15
问题 I'm looking at proc/ID/maps under embedded Linux, And I've noticed that some shared libraries appear few times at the memory map of a process why is it so ? 40094000-400d9000 r-xp 00000000 b3:09 723 /system/lib/libc.so 400d9000-400da000 ---p 00000000 00:00 0 400da000-400dc000 r-xp 00045000 b3:09 723 /system/lib/libc.so 400dc000-400de000 rwxp 00047000 b3:09 723 /system/lib/libc.so 400de000-400e9000 rwxp 00000000 00:00 0 400e9000-400ed000 r-xp 00000000 b3:09 770 /system/lib/libgccdemangle.so

What is alternative of create_proc_entry()

廉价感情. 提交于 2019-12-06 20:45:58
问题 As create_proc_entry function is deprecated, what is its replacement? I was trying to create a simple proc entry using create_proc_entry but got the this error: error: implicit declaration of function ‘create_proc_entry’ I grepped create_proc_entry in proc_fs.h but didn't find it there. Is there something that I'm missing or there's alternative to do this? 回答1: The newer functions are named proc_* . You can see their declarations in include/linux/proc_fs.h. In particular, proc_create creates