re: [suse-programming-e] How to read /proc/xxx/mem file??
Salman, I don't know how to do what you want either, but it almost sounds like you are trying to write a shared memory application. If so, shared memory is definitely the way to go, and standard across most varieties of UNIX. Of course, shared memory requires both programs have code to handle it, so you may not have that flexibility. Greg
Hi:
I am writing an application that needs to read another process's memory without affecting the target processor whatsoever. This is different from a source line debugger that has to stop the application. Someone told me that on Solaris, you fopen /proc/<process-id> file, fseek to the correct offset, and then fread the required # of bytes.
On Linux, things a different. There is not /proc/<process-id> file. Rather /proc/<process-id> is a directory in which you find a file named mem. If I cat this file for a process, I get nothing.
Anyone got any idea how to read this file? I wrote this program, but it fails.
I also heard (but did not confirm) that on Linux, you must first attach to the target process using the ptrace function. But doing so, stops the execution of the running process----I don't want that. This would be unacceptable.
#include <stdio.h> #include <unistd.h> //#include <sys/ptrace.h>
int main() { FILE* pFile; char buffer[4]; int temp; float value;
pFile = fopen("/proc/1673/mem", "rb+");
if(pFile == 0) return -1;
// I got the address of a global variable in the // process from objdump temp = fseek(pFile, 0x8050b50, SEEK_SET);
// this call fails :-( temp = fread(buffer, 4, 1, pFile);
value = *((float*)(buffer));
return 0; }
-- To unsubscribe, email: suse-programming-e-unsubscribe@suse.com For additional commands, email: suse-programming-e-help@suse.com Archives can be found at: http://lists/archive/suse-programming-e
participants (1)
-
Greg Freemyer