return system(cmd);
}
-/*
- * filter for scandir(). choose only thread identifiers
- */
-static int dir_select(const struct dirent *entry)
-{
- const char *c = entry->d_name;
- while (*c)
- if (!isdigit(*c++))
- return 0;
- return 1;
-}
-
-int get_threads(int pid, int **tids)
-{
- char buf[32];
- struct dirent **namelist;
- int cur, i, n, res;
-
- snprintf(buf, sizeof(buf), "/proc/%d/task", pid);
-
- n = scandir(buf, &namelist, dir_select, NULL);
- res = n;
- if (n < 0) {
- perror(buf);
- return -1;
- } else {
- *tids = malloc(sizeof(int)*n);
- if (*tids == NULL) {
- res = -1;
- goto exit;
- }
-
- i = 0;
- while (i < n) {
- cur = atoi(namelist[i]->d_name);
- (*tids)[i] = cur;
- }
- }
-
-exit:
- for (i = 0; i < n; i++)
- free(namelist[i]);
- free(namelist);
-
- return res;
-}
-
char *get_thread_states(const int *tids, int n)
{
int i;
int print_proc_maps(int pid);
/*
- * get thread identifiers of the process
- */
-int get_threads(int pid, int **tids);
-
-/*
* returns a pointer to dynamically allocated array of characters representing
* thread states as found in /proc/<pid>/status
*/