Rizin
unix-like reverse engineering framework and cli tools
darwin.c File Reference
#include <stdio.h>

Go to the source code of this file.

Functions

int pids_cmdline (int pid, char *cmdline)
 
int pids_sons_of_r (int pid, int recursive, int limit)
 

Function Documentation

◆ pids_cmdline()

int pids_cmdline ( int  pid,
char *  cmdline 
)

Definition at line 6 of file darwin.c.

6  {
7  int fd;
8  sprintf(cmdline, "/proc/%d/cmdline", pid);
9  fd = open(cmdline, O_RDONLY);
10  cmdline[0] = '\0';
11  if (fd != -1) {
12  rz_xread(fd, cmdline, 1024);
13  cmdline[1024] = '\0';
14  close(fd);
15  }
16 
17  return 0;
18 }
static static fork const void static count close
Definition: sflib.h:33
sprintf
Definition: kernel.h:365
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc pid
Definition: sflib.h:64
#define rz_xread(fd, buf, count)
Definition: rz_types.h:643
#define O_RDONLY
Definition: sftypes.h:486
static const z80_opcode fd[]
Definition: z80_tab.h:997

References close, fd, O_RDONLY, pid, rz_xread, and sprintf.

Referenced by pids_sons_of_r().

◆ pids_sons_of_r()

int pids_sons_of_r ( int  pid,
int  recursive,
int  limit 
)

Definition at line 21 of file darwin.c.

21  {
22  int p, mola, tmp, n = 0;
23  FILE *fd;
24  char tmp3[8];
25  char buf[128];
26  char tmp2[1024];
27  struct dirent *file;
28  DIR *dh;
29 
30  if (pid < 1)
31  return false;
32  dh = opendir("/proc/");
33  if (!dh) {
34  return false;
35  }
36 
37  while ((file = (struct dirent *)readdir(dh))) {
38  p = atoi(file->d_name);
39  if (p) {
40  sprintf(buf, "/proc/%s/stat", file->d_name);
41  fd = fopen(buf, "r");
42  if (fd) {
43  mola = 0;
44  fscanf(fd, "%d %s %s %d",
45  &tmp, tmp2, tmp3, &mola);
46  if (mola == pid) {
47  pids_cmdline(p, tmp2);
48  // for(i=0; i<recursive*2;i++)
49  // printf(" ");
50  cons_printf(" `- %d : %s (%s)\n",
51  p, tmp2, (tmp3[0] == 'S') ? "sleeping" : (tmp3[0] == 'T') ? "stopped"
52  : "running");
53  n++;
54  if (recursive < limit) {
55  n += pids_sons_of_r(p, recursive + 1, limit);
56  }
57  }
58  }
59  fclose(fd);
60  }
61  }
62  closedir(dh);
63  return n;
64 }
voidpf void * buf
Definition: ioapi.h:138
void * p
Definition: libc.cpp:67
int pids_sons_of_r(int pid, int recursive, int limit)
Definition: darwin.c:21
int pids_cmdline(int pid, char *cmdline)
Definition: darwin.c:6
static static fork const void static count static fd const char static mode const char static pathname const char static path const char static dev const char static group static getpid static getuid void void static data static pause const char static mode static sync const char const char static newpath const char static pathname unsigned long static filedes void static end_data_segment static handler static getegid char static len static pgid const char static path static newfd static getpgrp static euid const sigset_t static mask const char static len const gid_t static list const char const char static newpath const char static library readdir
Definition: sflib.h:120
static uint32_t const uint8_t uint32_t uint32_t limit
Definition: memcmplen.h:45
int n
Definition: mipsasm.c:19
string FILE
Definition: benchmark.py:21
Definition: sftypes.h:48
Definition: gzappend.c:170
static int file
Definition: z80asm.c:58

References fd, file, benchmark::FILE, limit, n, p, pid, pids_cmdline(), readdir, sprintf, and autogen_x86imm::tmp.