File: procargs.c

package info (click to toggle)
libgtop2 2.40.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 8,072 kB
  • sloc: ansic: 25,393; sh: 7,089; makefile: 418; perl: 268; xml: 179; sed: 16
file content (51 lines) | stat: -rw-r--r-- 731 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <glibtop.h>
#include <glibtop/procargs.h>

#include <stdlib.h>

#include <unistd.h>

static void show_args(pid_t pid, unsigned max_len)
{
  glibtop_proc_args buf;
  char ** const pargv = glibtop_get_proc_argv(&buf, pid, max_len);

  char **parg = pargv;

  printf("<%ld>\t", (long)pid);

  while(*parg)
    {
      printf("\"%s\" ", *parg);
      parg++;
    }

  putchar('\n');

  g_strfreev(pargv);
}


int main(int argc, char **argv)
{
  glibtop_init();

  show_args(getpid(), 0);
  show_args(getpid(), 15);

  while(*++argv)
    {
      pid_t pid = strtol(*argv, NULL, 10);
      show_args(pid, 0);
      show_args(pid, 15);
    }

  glibtop_close();

  return 0;
}