没有得到在psinfo_t结构的场pr_fname全过程名而来自中psinfo数据文件读取过程信息(的/ proc /%d /中psinfo)为从在solaris procfs.h结构psinfo_t 。psinfo_t Solaris没有在该领域包含完整的进程名
完全psinfo_t结构的定义存在于以下网站:
http://docs.oracle.com/cd/E19253-01/816-5174/6mbb98ui2/index.html
只有进程名是小于等于15个字符,然后我得到了全过程名其他明智的,如果进程名是更超过15个字符,那么我只能获取前15个字符的进程名称,其余字符会被截断。
我使用的代码如下:
#include <iostream>
#include <cstdlib>
#include <procfs.h>
#include <fstream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
// get the pid from command line
int pid = atoi(argv[1]);
// create the pstatus struct from procfs
psinfo_t info;
char file[100];
sprintf(file, "/proc/%d/psinfo", pid);
ifstream in(file);
if (in)
{
in.read((char*)&info, sizeof(psinfo_t));
in.close();
cout << "My Name: " << info.pr_fname << endl;
}
else
{
cout << "Process Not Exists!" << endl;
}
return 0;
}
我一定要读procfs的文件系统的其他一些文件(比其他中psinfo),以获得完整的进程名。 另外,如果我使用命令行belwo ps命令,然后我能够得到充分的进程名:
ps -p 4970 -o comm
,但我不希望我的代码中执行ps命令来获得进程名。 我很好奇ps二进制文件正在拾取进程名称。
是否有一个预定义的结构,我可以在其中存储此映射文件的数据。 – mSatyam
@mSatyam它与您在问题中链接的相同'proc.4'手册页上。 –
我试图将地图数据文件读入prmap_t结构中,但是当我打印数据成员pr_mapname时,它是一个空字符串。你是否打算让我去做别的事情?我做对了吗? – mSatyam