struct kinfo_proc *result, *ptr;
int name[] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0 };
size_t length, i;
result = NULL;
length = 0;
if (sysctl((int *)name,(sizeof(name)/sizeof(*name)) - 1, NULL, &length, NULL, 0) == -1)
return 0;
if ((result = (kinfo_proc *)malloc(length)) == NULL)
return 0;
if (sysctl((int *)name, (sizeof(name)/sizeof(*name)) - 1, result, &length, NULL, 0) == -1)
{
free(result);
return 0;
}
for (i = 0, ptr = result; (i < (length/sizeof(kinfo_proc)); ++i, ++ptr)
{
// ptr->kp_proc.p_pid contains the pid
// ptr->kp_proc.p_comm contains the name
pid_t iCurrentPid = ptr->kp_proc.p_pid;
if (strncmp(processName, ptr->kp_proc.p_comm, MAXCOMLEN) == 0)
{
free(sProcesses);
return iCurrentPid;
}
}
free(result);
struct kinfo_proc *result, *ptr;
int name[] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0 };
size_t length, i;
result = NULL;
length = 0;
if (sysctl((int *)name,(sizeof(name)/sizeof(*name)) - 1, NULL, &length, NULL, 0) == -1)
return 0;
if ((result = (kinfo_proc *)malloc(length)) == NULL)
return 0;
if (sysctl((int *)name, (sizeof(name)/sizeof(*name)) - 1, result, &length, NULL, 0) == -1)
{
free(result);
return 0;
}
for (i = 0, ptr = result; (i < (length/sizeof(kinfo_proc)); ++i, ++ptr)
{
// ptr->kp_proc.p_pid contains the pid
// ptr->kp_proc.p_comm contains the name
pid_t iCurrentPid = ptr->kp_proc.p_pid;
if (strncmp(processName, ptr->kp_proc.p_comm, MAXCOMLEN) == 0)
{
free(sProcesses);
return iCurrentPid;
}
}
free(result);
To copy to clipboard, switch view to plain text mode
QDirIterator it("/proc", QDirIterator::Subdirectories)
while (it.hasNext())
{
it.next();
if (child.fileName() == ".." || child.fileName() == ".")
continue;
...
}
QDirIterator it("/proc", QDirIterator::Subdirectories)
while (it.hasNext())
{
it.next();
QFileInfo child = it.fileInfo();
if (child.fileName() == ".." || child.fileName() == ".")
continue;
...
}
To copy to clipboard, switch view to plain text mode
Bookmarks