本文整理汇总了C++中ProcessPtr::pid方法的典型用法代码示例。如果您正苦于以下问题:C++ ProcessPtr::pid方法的具体用法?C++ ProcessPtr::pid怎么用?C++ ProcessPtr::pid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProcessPtr
的用法示例。
在下文中一共展示了ProcessPtr::pid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: do_procs
static int do_procs(SnapshotPtr &snap, char *args[])
{
list<ProcessPtr> procs;
list<ProcessPtr>::iterator it;
procs = snap->procs();
Sizes::scale_kbytes();
cout << "PID";
for (int i = 0; i < Sizes::NUM_SIZES; ++i) {
cout << "\t" << Sizes::size_name(i);
}
cout << "\t" << "CMD";
cout << "\n";
for (it = procs.begin(); it != procs.end(); ++it) {
ProcessPtr proc = *it;
SizesPtr sizes = proc->sizes();
cout << proc->pid();
for (int i = 0; i < Sizes::NUM_SIZES; ++i) {
cout << "\t" << sizes->sval(i);
}
cout << "\t" << proc->cmdline();
cout << "\n";
}
return 0;
}
示例2: run
bool ExmapTest::run()
{
SysInfoPtr sysinfo(new LinuxSysInfo);
Snapshot snap(sysinfo);
is(snap.num_procs(), 0, "zero procs before load");
ok(snap.load(), "can load snapshot");
ok(snap.num_procs() > 0, "some procs after load");
list<ProcessPtr> allprocs = snap.procs();
ok(!allprocs.empty(), "can get a list of procs");
list<ProcessPtr>::iterator proc_it;
list<ProcessPtr> procs;
bool failed_to_get_sizes = false;
SizesPtr sizes;
for (proc_it = allprocs.begin(); proc_it != allprocs.end(); ++proc_it) {
string cmdline = (*proc_it)->cmdline();
if (cmdline== SA_EXE) {
procs.push_back(*proc_it);
}
sizes = (*proc_it)->sizes();
if (!sizes) {
failed_to_get_sizes = true;
}
}
ok(!failed_to_get_sizes, "can get sizes for every proc");
is((int) procs.size(), NUM_INSTANCES, "can find all our sharedarray procs");
ProcessPtr proc = procs.front();
sizes = proc->sizes();
ok(sizes->val(Sizes::VM) > NUM_ARRAYS * ARRAY_SIZE, "image is big enough");
double ps_size = get_pid_size_from_ps(proc->pid());
is_approx_rel(sizes->val(Sizes::VM),
ps_size,
0.001,
"exmap info matches ps output");
ok(sizes->val(Sizes::RESIDENT) > 0, "nonzero resident size");
ok(sizes->val(Sizes::EFFECTIVE_RESIDENT) > 0, "nonzero eff resident size");
ok(sizes->val(Sizes::EFFECTIVE_RESIDENT) < sizes->val(Sizes::RESIDENT),
"effective is smaller than eff resident");
ok(sizes->val(Sizes::MAPPED) > 0, "nonzero mapped size");
ok(sizes->val(Sizes::EFFECTIVE_MAPPED) > 0, "nonzero eff mapped size");
ok(sizes->val(Sizes::EFFECTIVE_MAPPED) < sizes->val(Sizes::MAPPED),
"effective is smaller than eff mapped");
list<FilePtr> files;
list<FilePtr>::iterator file_it;
list<FilePtr> all_files = snap.files();
ok(all_files.size() > 0, "can find some files");
Regexp re;
re.compile(SA_LIB + "$");
failed_to_get_sizes = false;
for (file_it = all_files.begin(); file_it != all_files.end(); ++file_it) {
string name = (*file_it)->name();
if (re.matches(name)) {
files.push_back(*file_it);
}
sizes = (*file_it)->sizes();
if (!sizes) {
failed_to_get_sizes = true;
}
}
ok(!failed_to_get_sizes, "can get sizes for every file");
is((int) files.size(), 1, "shared lib only listed once");
FilePtr shlib_file = files.front();
ok(shlib_file->is_elf(), "shared lib recognised as elf file");
list<ProcessPtr> procs_per_file = shlib_file->procs();
is((int) procs_per_file.size(), NUM_INSTANCES,
"right number of procs mapping the file");
for (proc_it = procs_per_file.begin();
proc_it != procs_per_file.end();
++proc_it) {
ok(proc->cmdline() == SA_EXE, "each proc has correct cmdline");
}
for (proc_it = procs.begin();
proc_it != procs.end();
++proc_it) {
sizes = proc->sizes(shlib_file);
long arrays_size = NUM_ARRAYS * ARRAY_SIZE;
float delta = std::abs(arrays_size - (long) sizes->val(Sizes::VM));
delta /= arrays_size;
ok(delta < 0.01, "Shared lib has correct size in each proc");
}
Elf::SectionPtr text = shlib_file->elf()->section(".text");
ok(text, "can find text section");
ok(text->size() > 0, "text section has nonzero size");
sizes = procs.front()->sizes(shlib_file, text->mem_range());
/// This appears to be compiler and system dependent...
/*
//.........这里部分代码省略.........