C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 07-26-2007, 07:02 AM   #1
C++ Programmer
 
Join Date: Aug 2005
Posts: 39
ReadProcessMemory/WriteProcessMemory Linux equivalent?

Hi,

The Win32 Api has the functions ReadProcessMemory and WriteProcessMemory, to read/write the memopry of a certain process.

But I'm a Linux user, and after a lot of searching I can't find equivalent functions that work on Linux.

Do they actually exists, and if so, do I need a library or something?
MrLucky is offline   Reply With Quote
Old 07-26-2007, 08:58 AM   #2
and the hat of Jobseeking
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,705
http://www.linuxmanpages.com/man2/ptrace.2.php
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.

Salem is offline   Reply With Quote
Old 07-27-2007, 03:30 AM   #3
C++ Programmer
 
Join Date: Aug 2005
Posts: 39
woot thanks a lot!

Btw, is there any function to ge a list of running processes with their pid's?

Last edited by MrLucky; 07-27-2007 at 03:33 AM.
MrLucky is offline   Reply With Quote
Old 07-27-2007, 06:35 AM   #4
Cat without Hat
 
CornedBee's Avatar
 
Join Date: Apr 2003
Posts: 8,492
No, you have to browse the /proc directory.

Just what are you trying to do?
__________________
All the buzzt!
CornedBee

"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
CornedBee is offline   Reply With Quote
Old 07-27-2007, 06:44 AM   #5
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
If it's a process that you started, then you can also do "jobs" or some such. Or "ps". ("ps ax" will list ALL processes in the system).

But bear in mind that ptrace only works on processes that you own, unless you are root, so you can't poke around in someone elses processes (which is the same in Windows of course).

--
Mats
matsp is offline   Reply With Quote
Old 07-27-2007, 08:01 AM   #6
C++ Programmer
 
Join Date: Aug 2005
Posts: 39
Quote:
Originally Posted by matsp View Post
If it's a process that you started, then you can also do "jobs" or some such. Or "ps". ("ps ax" will list ALL processes in the system).

But bear in mind that ptrace only works on processes that you own, unless you are root, so you can't poke around in someone elses processes (which is the same in Windows of course).

--
Mats
Ok, I think I'll use the ps command then

Quote:
Originally Posted by CornedBee View Post
No, you have to browse the /proc directory.

Just what are you trying to do?
Trying to create a memory viewer/editor for Linux.
MrLucky is offline   Reply With Quote
Old 07-27-2007, 08:44 AM   #7
Senior software engineer
 
brewbuck's Avatar
 
Join Date: Mar 2007
Location: Portland, OR
Posts: 5,768
Quote:
Originally Posted by CornedBee View Post
No, you have to browse the /proc directory.
If he wants to change the memory of another process, he CAN do it with ptrace(). The alternate method is accessing /proc/xxx/mem, but under many kernels, this access is turned off, or restricted to read-only.
brewbuck is offline   Reply With Quote
Old 07-27-2007, 09:36 AM   #8
Registered User
 
Join Date: Nov 2006
Posts: 510
Quote:
Originally Posted by brewbuck View Post
If he wants to change the memory of another process, he CAN do it with ptrace(). The alternate method is accessing /proc/xxx/mem, but under many kernels, this access is turned off, or restricted to read-only.
He has just to use the program lcap to enable the CAP_SYS_PTRACE capability. This can be done at run time without changing the kernel
pheres is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Equivalent to volume serial number in linux Elkvis Linux Programming 8 06-30-2009 08:46 PM
Linux equivalent to Win32 ShellExecute BobS0327 Linux Programming 4 06-07-2006 04:35 AM
Linux equivalent of con dwks Linux Programming 3 11-12-2005 11:58 AM
Linux equivalent to CreateDirectory Rak'kar Linux Programming 2 07-10-2004 12:04 PM
.bat equivalent for linux ichijoji Linux Programming 8 03-07-2004 08:06 AM


All times are GMT -6. The time now is 10:17 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22