Markus Rechberger / C / Resolve Filename
 
StartSeite | MarkusRechberger/ C/ | Neues | TestSeite | ForumSeite | Teilnehmer | Kategorien | Index | Hilfe | Einstellungen | Ändern

Veränderung (zum vorhergehenden Autor) (Änderung, Korrektur, Normalansicht)

Verändert: 1c1,54
Beschreibe hier die neue Seite.
== Determine the filename of an open file by the fd ==

[[Code]
#include <sys/param.h>
#include <sys/pstat.h>
#include <sys/unistd.h>
#include <stdio.h>

int main( int argc, char *argv[] )
{
#define BURST ((size_t)10)
struct pst_fileinfo2 psf[BURST];
int i, count;
int idx = 0; /* index within the context */

if ( argc != 2 )
{
printf( "args: <pid>\n" );
exit( 1 );
}
pid_t target = atoi( argv[1] );

(void)printf("Open files for process PID %d\n", target);

/* loop until all fetched */
while ((count = pstat_getfile2(psf, sizeof(struct pst_fileinfo2),
BURST, idx, target)) > 0) {
/* process them (max of BURST) at a time */
for (i = 0; i < count; i++) {
(void)printf("fd #%d\tFSid %x:%x\tfileid %d\n",
psf[i].psf_fd,
psf[i].psf_id.psf_fsid.psfs_id,
psf[i].psf_id.psf_fsid.psfs_type,
psf[i].psf_id.psf_fileid);
}

/*
* Now go back and do it again, using the
* next index after the current 'burst'
*/
idx = psf[count-1].psf_fd + 1;
}
if (count == -1)
perror("pstat_getfile2()");

#undef BURST
}
]

[[Code]
#include <unistd.h>
char *ttyname(int fildes);
]


Determine the filename of an open file by the fd

#include <sys/param.h>
#include <sys/pstat.h>
#include <sys/unistd.h>
#include <stdio.h>

int main( int argc, char *argv[] )
{
   #define BURST ((size_t)10)
   struct pst_fileinfo2 psf[BURST];
   int i, count;
   int idx = 0; /* index within the context */

   if ( argc != 2 )
   {
       printf( "args: <pid>\n" );
       exit( 1 );
   }
   pid_t target = atoi( argv[1] );

   (void)printf("Open files for process PID %d\n", target);

   /* loop until all fetched */
   while ((count = pstat_getfile2(psf, sizeof(struct pst_fileinfo2),
                                 BURST, idx, target)) > 0) {
            /* process them (max of BURST) at a time */
            for (i = 0; i < count; i++) {
                 (void)printf("fd #%d\tFSid %x:%x\tfileid %d\n",
                        psf[i].psf_fd,
                        psf[i].psf_id.psf_fsid.psfs_id,
                        psf[i].psf_id.psf_fsid.psfs_type,
                        psf[i].psf_id.psf_fileid);
            }

            /*
            * Now go back and do it again, using the
             * next index after the current 'burst'
             */
             idx = psf[count-1].psf_fd + 1;
   }
   if (count == -1)
            perror("pstat_getfile2()");

   #undef BURST
}

   #include <unistd.h>
  char *ttyname(int fildes);


StartSeite | MarkusRechberger/ C/ | Neues | TestSeite | ForumSeite | Teilnehmer | Kategorien | Index | Hilfe | Einstellungen | Ändern
Text dieser Seite ändern (zuletzt geändert: 16. April 2005 18:26 (diff))
Suchbegriff: gesucht wird
im Titel
im Text