Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
HiGarfield committed Sep 28, 2024
1 parent c6fc27d commit 4412766
Showing 1 changed file with 1 addition and 27 deletions.
28 changes: 1 addition & 27 deletions src/process_iterator_apple.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,38 +95,12 @@ int init_process_iterator(struct process_iterator *it, struct process_filter *fi
return 0;
}

int get_process_path(int pid, char *pathbuf, size_t buf_size)
{
int mib[4];
size_t len;
struct kinfo_proc kp;

/* Set up the mib array */
mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_PID;
mib[3] = pid;

/* Get process info */
len = sizeof(kp);
if (sysctl(mib, 4, &kp, &len, NULL, 0) == -1)
{
perror("sysctl");
return -1;
}

/* Copy the executable path to pathbuf */
strncpy(pathbuf, kp.kp_proc.p_comm, buf_size);

return 0;
}

static void pti2proc(struct proc_taskallinfo *ti, struct process *process)
{
process->pid = ti->pbsd.pbi_pid;
process->ppid = ti->pbsd.pbi_ppid;
process->cputime = ti->ptinfo.pti_total_user / 1e6 + ti->ptinfo.pti_total_system / 1e6;
get_process_path(ti->pbsd.pbi_pid, process->command, sizeof(process->command));
proc_pidpath(ti->pbsd.pbi_pid, process->command, sizeof(process->command));
process->max_cmd_len = sizeof(process->command) - 1;
}

Expand Down

0 comments on commit 4412766

Please sign in to comment.