diff options
author | Benoît Dejean <bdejean@src.gnome.org> | 2005-01-10 08:43:04 +0000 |
---|---|---|
committer | Benoît Dejean <bdejean@src.gnome.org> | 2005-01-10 08:43:04 +0000 |
commit | 7ca4171652dff239b35b1959bb7a32a2d066dca8 (patch) | |
tree | 5bf03f60ca927540b061a57885d85300bf250109 /examples | |
parent | 1537eea7e5abfff849d1b239c15446699668811b (diff) | |
download | libgtop-7ca4171652dff239b35b1959bb7a32a2d066dca8.tar.gz |
New feature by nick@reloco.com.ar (Nicolás Lichtmaier).
* configure.in:
* examples/.cvsignore:
* examples/Makefile.am:
* examples/openfiles.c: (show_open_files), (main):
* features.def:
* include/glibtop/Makefile.am:
* include/glibtop/command.h:
* include/glibtop/procopenfiles.h:
* include/glibtop/sysdeps.h:
* include/glibtop/union.h:
* structures.def:
* sysdeps/linux/Makefile.am:
* sysdeps/linux/procopenfiles.c: (glibtop_init_proc_open_files_s),
(get_socket_endpoint), (glibtop_get_proc_open_files_s):
* sysdeps/stub/Makefile.am:
* sysdeps/stub/procopenfiles.c: (glibtop_init_proc_open_files_s),
(glibtop_get_proc_open_files_s):
New feature by nick@reloco.com.ar (Nicolás Lichtmaier).
glibtop_get_open_files(pid) -> list of files by process.
TODO: Add documentation.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/.cvsignore | 3 | ||||
-rw-r--r-- | examples/Makefile.am | 11 | ||||
-rw-r--r-- | examples/openfiles.c | 64 |
3 files changed, 76 insertions, 2 deletions
diff --git a/examples/.cvsignore b/examples/.cvsignore index f7ec2055..236bbd67 100644 --- a/examples/.cvsignore +++ b/examples/.cvsignore @@ -22,4 +22,5 @@ df df_static netlist netlist_static - +openfiles +openfiles_static diff --git a/examples/Makefile.am b/examples/Makefile.am index ab41a46c..a748f224 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -8,11 +8,12 @@ DEFS = @DEFS@ noinst_PROGRAMS = first second pprint procargs df netlist \ mountlist procmap netload sysdeps timings \ + openfiles \ @static_targets@ @smp_examples@ EXTRA_PROGRAMS = first_static second_static \ mountlist_static procmap_static \ - smp smp_static \ + smp smp_static openfiles_static \ netload_static sysdeps_static \ timings_static pprint_static procargs_static \ df_static netlist_static @@ -108,3 +109,11 @@ netlist_static_LDADD = $(netlist_LDADD) netlist_static_LDFLAGS = -static +openfiles_SOURCES = openfiles.c +openfiles_LDADD = $(top_builddir)/lib/libgtop-2.0.la + +openfiles_static_SOURCES = $(openfiles_SOURCES) +openfiles_static_LDADD = $(openfiles_LDADD) +openfiles_static_LDFLAGS = -static + + diff --git a/examples/openfiles.c b/examples/openfiles.c new file mode 100644 index 00000000..028c60dc --- /dev/null +++ b/examples/openfiles.c @@ -0,0 +1,64 @@ +#include <glibtop.h> +#include <glibtop/procopenfiles.h> + +#include <stdlib.h> + +#include <unistd.h> + +static void show_open_files(pid_t pid) +{ + glibtop_proc_open_files buf; + glibtop_open_files_entry *files; + unsigned i; + + files = glibtop_get_proc_open_files(&buf, pid); + + printf("<%ld>\n", (long)pid); + + for(i = 0; i < buf.number; ++i) + { + printf("\tfd = %d\t", files[i].fd); + + switch(files[i].type) + { + case GLIBTOP_FILE_TYPE_FILE: + printf("file \"%s\"\n", files[i].info.file.name); + break; + + case GLIBTOP_FILE_TYPE_PIPE: + printf("pipe\n"); + break; + + case GLIBTOP_FILE_TYPE_INETSOCKET: + printf("socket %s:%d\n", files[i].info.sock.dest_host, files[i].info.sock.dest_port); + break; + + case GLIBTOP_FILE_TYPE_LOCALSOCKET: + printf("localsocket\n"); + break; + } + } + + putchar('\n'); + + g_free(files); +} + + +int main(int argc, char **argv) +{ + glibtop_init(); + + show_open_files(getpid()); + + while(*++argv) + { + pid_t pid = strtol(*argv, NULL, 10); + show_open_files(pid); + } + + glibtop_close(); + + return 0; +} + |