psinfo_tsolaris的字段中不包含完整的进程名称
psinfo_t solaris does not contain full process name in its field
从solaris中的procfs.h将进程信息从psinfo数据文件(/proc/%d/psinfo(读取到结构体psinfo_t时,未在psinfo_tstruct的字段pr_fname中获取完整进程名称。
完整的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二进制文件是从哪里获得进程名称的。
根据源代码:,psinfo_t
结构的pr_fname
字段长16字节
#define PRFNSZ 16 /* Maximum size of execed filename */
因此,它实际上将被截断为最多15个字符。
您可以从/proc/PID/map
中获取实际二进制文件的名称。对于32位进程,exec'd二进制文件将映射到地址0x00010000
。
您可以在以下位置浏览ps
的源代码:http://src.illumos.org/source/xref/illumos-gate/usr/src/cmd/ps/如果你想看看它在哪里找到数据。
Solaris 11.3 SRU 5引入了包含完整命令名的/proc/<pid>/execname
,因此您可以检查该文件是否存在并在存在时使用它,否则请返回到有限的pr_fname
。
请参阅Solaris 11.3 SRU 5.6:ps(1(和/proc/<pid>/{cmdline,environ,execname}获取详细信息。
- 限定的依赖名称查找,其中包含基类的注入类名
- 当包含成员函数名为errno和cerrno时,g++7编译错误
- 进程为包含double但不包含int的模板返回了-103741819(0xC0000005)
- 包含字符串的结构的 Boost 进程间向量是否需要特殊的分配器?
- 令牌之前的预期类名 '{' - 包含头文件和 CPP 文件
- 为什么名为互斥锁文档的加速间进程说每个进程都应该有自己的名称互斥锁?
- MFC - 主窗口/进程的随机名称和类名
- 为包含通用字符名的字符串文字省略u8前缀
- 是否可以在编译时获得一个包含命名空间和类名的字符串
- Android NDK构建共享库-中止-停止.local_module_filename不能包含文件扩展名
- psinfo_tsolaris的字段中不包含完整的进程名称
- JVM 无法按预期方式处理包含名为 "Node" 的类的 JNI C++代码
- c++传递一个.txt文件,其中包含函数名和参数
- 从HWND获取图标进程,进程名或其他进程标识符
- 如何包含Boost.进程间和Boost.DateTime
- 如何在winapi窗口中获得当前活动窗口的进程名?
- Windows 8/10中活动窗口的进程名
- 如何在不枚举进程的情况下,通过c++从进程id中获取进程名
- 在vc++中获取活动进程名
- 从“进程名”中获取进程ID