- 论坛徽章:
- 0
|
回复 #1 swxlion 的帖子
这是一个x86/FreeBSD 4.5-RELEASE系统中利用proc获取绝对路径的例子
--------------------------------------------------------------------------
/*
* gcc -Wall -pipe -g -static -o myprog_4 myprog_4.c
*/
#include
#include
#include
#include
#define MAXBUFSIZE 1024
int main ( int argc, char * argv[] )
{
char proc[64];
char buf[ MAXBUFSIZE ];
int count;
sprintf( proc, "/proc/%d/file", ( unsigned int )getpid() );
count = readlink( proc, buf, MAXBUFSIZE );
if ( count < 0 || count >= MAXBUFSIZE )
{
printf( "Failed\n" );
return( EXIT_FAILURE );
}
buf[ count ] = ’\0’;
printf( "%s -> [%s]\n", proc, buf );
return( EXIT_SUCCESS );
} /* end of main *% |
|