mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 19:41:16 +00:00
Add virProcessGetPids to get all tasks of a process
This function gets all the PIDs listed in /proc/PID/task. This will be needed at least to move all qmeu-nbd tasks to the container cgroup.
This commit is contained in:
parent
29230951f1
commit
e44b0269c9
@ -1988,6 +1988,7 @@ virProcessAbort;
|
|||||||
virProcessExitWithStatus;
|
virProcessExitWithStatus;
|
||||||
virProcessGetAffinity;
|
virProcessGetAffinity;
|
||||||
virProcessGetNamespaces;
|
virProcessGetNamespaces;
|
||||||
|
virProcessGetPids;
|
||||||
virProcessGetStartTime;
|
virProcessGetStartTime;
|
||||||
virProcessKill;
|
virProcessKill;
|
||||||
virProcessKillPainfully;
|
virProcessKillPainfully;
|
||||||
|
@ -600,6 +600,53 @@ virProcessGetAffinity(pid_t pid ATTRIBUTE_UNUSED)
|
|||||||
#endif /* HAVE_SCHED_GETAFFINITY */
|
#endif /* HAVE_SCHED_GETAFFINITY */
|
||||||
|
|
||||||
|
|
||||||
|
int virProcessGetPids(pid_t pid, size_t *npids, pid_t **pids)
|
||||||
|
{
|
||||||
|
int ret = -1;
|
||||||
|
char *taskPath = NULL;
|
||||||
|
DIR *dir = NULL;
|
||||||
|
int value;
|
||||||
|
struct dirent *ent;
|
||||||
|
|
||||||
|
*npids = 0;
|
||||||
|
*pids = NULL;
|
||||||
|
|
||||||
|
if (virAsprintf(&taskPath, "/proc/%llu/task",
|
||||||
|
(unsigned long long)pid) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (!(dir = opendir(taskPath)))
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
while ((value = virDirRead(dir, &ent, taskPath)) > 0) {
|
||||||
|
pid_t tmp_pid;
|
||||||
|
|
||||||
|
/* Skip . and .. */
|
||||||
|
if (STRPREFIX(ent->d_name, "."))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (virStrToLong_i(ent->d_name, NULL, 10, &tmp_pid) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (VIR_APPEND_ELEMENT(*pids, *npids, tmp_pid) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
if (!dir)
|
||||||
|
closedir(dir);
|
||||||
|
VIR_FREE(taskPath);
|
||||||
|
if (ret < 0)
|
||||||
|
VIR_FREE(*pids);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int virProcessGetNamespaces(pid_t pid,
|
int virProcessGetNamespaces(pid_t pid,
|
||||||
size_t *nfdlist,
|
size_t *nfdlist,
|
||||||
int **fdlist)
|
int **fdlist)
|
||||||
|
@ -60,6 +60,8 @@ int virProcessSetAffinity(pid_t pid, virBitmapPtr map);
|
|||||||
|
|
||||||
virBitmapPtr virProcessGetAffinity(pid_t pid);
|
virBitmapPtr virProcessGetAffinity(pid_t pid);
|
||||||
|
|
||||||
|
int virProcessGetPids(pid_t pid, size_t *npids, pid_t **pids);
|
||||||
|
|
||||||
int virProcessGetStartTime(pid_t pid,
|
int virProcessGetStartTime(pid_t pid,
|
||||||
unsigned long long *timestamp);
|
unsigned long long *timestamp);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user