* 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.
65 lines
1.0 KiB
C
65 lines
1.0 KiB
C
#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;
|
|
}
|
|
|