Thread: ReadProcessMemory/WriteProcessMemory Linux equivalent?

  1. #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?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #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.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    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

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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

  6. #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.

  7. #7
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    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.

  8. #8
    Registered User
    Join Date
    Nov 2006
    Posts
    519
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

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