pmap can not get shm information when parent process close stdin.
The parent process code is like this
#include <stdio.h>
int main(int argc, char *argv[]) {
close(0);
if (fork() == 0) {
execl("/usr/bin/pmap", "pmap", "3357", NULL);
}
return 0;
}
where pid 3375 is a process which owns one shm section.
The output of the program above is here.
[root@VM-196-152-centos ~/test/issue]# ./test
[root@VM-196-152-centos ~/test/issue]# 3357: ./a.out
...
00007f45074f0000 4K r--s- SYSV00000000 (deleted)
00007f45074f1000 4K rw--- [ anon ]
...
total 7340K
We can see that the shm section is not parsed correctly.
Which should be parsed as below:
[root@VM-196-152-centos ~/test/issue]# pmap 3357
3357: ./a.out
...
00007f45074f0000 4K r--s- [ shmid=0x288026 ]
...
total 7340K
This is because in file pmap.c, when doing the function discover_shm_minor, it reopens stdin which has already been closed by the parent process.
Is this a bug or it is just designed like this?
Edited by freelw