Portál AbcLinuxu, 15. července 2025 12:14
cat /proc/PID/fd/cislo_fd_zodpovedajuce_socketuale to funguje len s fd ktore su fyzicky na disku. Zaujmalo by ma tiez, ci a ako je mozne precitat subor /proc/PID/mem Za nakopnutie diki.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define STR_SIZE 256
char data[STR_SIZE];
int main(int argc,char **argv)
{
char file[STR_SIZE];
char str[STR_SIZE];
int fd;
sprintf(file,"/proc/%d/mem",getpid());
fd = open(file,O_RDONLY);
strcpy(data,"Hello world!\n");
lseek(fd,(int)&data,SEEK_SET);
read(fd,str,STR_SIZE);
printf("str=%s\n",str);
strcpy(data,"Ahoj svet!");
lseek(fd,(int)&data,SEEK_SET);
read(fd,str,STR_SIZE);
printf("str=%s",str);
close(fd);
return 0;
}
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.