Sponsored Content
Top Forums Programming [FreeBSD] ptrace( ) - Device busy Post 34024 by Driver on Thursday 30th of January 2003 01:15:05 PM
Old 01-30-2003
[FreeBSD] ptrace( ) - Device busy

Hello,
I'm trying to obtain process memory contents using ptrace( ) on FreeBSD 4.7. I know this is neither portable nor clean, yet I'd really like to get it to work... I read the manual help page and did a google search, but couldn't find anything helpful.
First, the code I'm using to read an integer:

Code:
#include <sys/types.h>
#include <sys/ptrace.h>
#include <sys/wait.h>
#include <unistd.h>
#include <signal.h>
#include <errno.h>
#include <stdio.h>

#define ERR( msg, pid ) do { \
                          fprintf( stderr, "%s: %s (errno = %d)\n", \
                            msg, strerror( errno ), errno ); \
                          waitpid( pid, NULL, 0 ); \
                          return 1; \
                        } while( 0 );

int main( ) {
  pid_t child;
  int   i;
  child = fork( );
  if( child == -1 ) {
    perror( "fork" );
    return 1;
  } else if( child == 0 ) {
    execl( "./foobar", NULL );
    perror( "execl" );
    return 1;
  }
  printf( "Attaching to %d\n", child );
  rc = ptrace( PT_ATTACH, child, ( void* )0, 0 );
  if( rc == -1 ) {
    ERR( "ptrace", child );
  }
  printf( "Stopping...\n" );
  if( kill( child, SIGSTOP ) != 0 ) {
    ERR( "kill", child );
  }
  printf( "Attempting to read...\n" );
  rc = ptrace( PT_READ_I, child, ( void* )0, 0 );
  if( rc == -1 ) {
    ERR( "ptrace", child );
  }
  printf( "0x0: %d\n", rc );
  return 0;
}

And the source for the exec'd ``foobar'':

Code:
#include <unistd.h>

int main( ) {
  pause( );
  return 0;
}

The output I get when I execute the program is this:

Code:
Attaching to 5994
Stopping...
Attempting to read...
ptrace: Device busy (errno = 16)

I have tried several variations using PT_READ_I and PT_READ_D (although my manual help page states these are identical on FreeBSD), using several addresses - I always get this error.
Can anyone see what I'm doing wrong here?
Thanks in advance.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

umount, device busy, but..

I'm trying to unmount a file system, but umount says the device is busy. A fuser -c /myfs tells me that nothing on this fs is in use. Any idea? Oh, and btw, why isn't my signature beeing displayed? Show user's signature is enabled and I have entered one :/ (10 Replies)
Discussion started by: sTorm
10 Replies

2. HP-UX

Cannot umount - device busy

Anyone have any idea why I cannot umount a directory even though fuser shows no process attached to it? fuser -cu /data/oracle/GMPSHRDM/export /data/oracle/GMPSHRDM/export: umount /data/oracle/GMPSHRDM/export umount: cannot unmount /data/oracle/GMPSHRDM/export : Device busy umount:... (2 Replies)
Discussion started by: keelba
2 Replies

3. UNIX for Dummies Questions & Answers

Device or resource busy??

Hi, I'm trying to do a sharity mount to mount a terastation network drive. I'm getting a Device or resource busy message after my mount command. Please see output below... # /usr/local/sharity3/bin/sharity mount smb://labbackup01/bakup_data /mnt/labbackup01 Device or resource busy.... (2 Replies)
Discussion started by: orahi001
2 Replies

4. UNIX Desktop Questions & Answers

cygwin /dev/ttyS2: Device or resource busy

Ciao a tutti!!! il mio problema è questo: sto cercando di inviare dei comandi AT da PC a cellulare utilizzando il bluetooth e cygwin e vorrei visualizzare le risposte nella shell bash. Per farlo apro due terminali utilizzando le seguente istruzioni: xterm & Sul primo scrivo cat /dev/ttyS2 ... (0 Replies)
Discussion started by: blianna
0 Replies

5. UNIX and Linux Applications

/dev/ttyS2 device or resource busy

Ciao a tutti!!! il mio problema è questo: sto cercando di inviare dei comandi AT da PC a cellulare utilizzando il bluetooth e cygwin e vorrei visualizzare le risposte nella shell bash. Per farlo apro due terminali utilizzando le seguente istruzioni: xterm & Sul primo scrivo cat /dev/ttyS2 ... (1 Reply)
Discussion started by: blianna
1 Replies

6. UNIX Desktop Questions & Answers

cygwin error device or resource busy

Hello!!! My problem is: i'm trying to send At commands from Pc to mobile phone using bluetooth and cygwin and i would like to read the device's answers on the shell bash. And so, i open two terminals in this way: xterm & In the first i write: cat /dev/ttyS2 because the device is... (9 Replies)
Discussion started by: blianna
9 Replies

7. Solaris

CDROM will not eject - says device busy

Hi, I've seen similar posts on this board about ejecting CDROMs but I've tried the solutions people suggested but still cannot eject the CD. It's stuck in a production box so I can't reboot it... bash-3.00# eject -f cdrom /vol/dev/dsk/c0t0d0/sol_10_106_sparc/s0: Device busy bash-3.00#... (14 Replies)
Discussion started by: jimmy54321
14 Replies

8. Hardware

/dev/ttyS0: Device or resource busy

hello to everybody I have Ubuntu Lucid 10.04 installed on my Desktop and I have a PCI serial card in my computer and it has only one serial port. Actually I want to use this serial port for the serial communication and for that I executed this command : $ setserial -g /dev/ttyS and I... (0 Replies)
Discussion started by: piyush011
0 Replies

9. HP-UX

Failed to open tape device /dev/rmt/0mn:Device busy (errno = 16)

Hi, Unable to make tape backup, please help. /opt/ignite/bin/make_tape_recovery -a /dev/rmt/?mn -I -v -m tar -x inc_entire=vg00 * Creating local directories for configuration files and archive. ======= 04/25/16 16:28:08 IST Started /opt/ignite/bin/make_tape_recovery. (Mon... (4 Replies)
Discussion started by: anuragr
4 Replies

10. UNIX for Beginners Questions & Answers

Mount : Device busy

mount -f nfs 1234:/export/ert /der/fr/ert mount : /der/fr/ert: device busy normally I will then do an fuser filesystem and kill the pids, which I did. now if I do an fuser /der/fr/ert I get the mount point and no pid > fuser /der/fr/ert /der/fr/ert: but it... (1 Reply)
Discussion started by: goya
1 Replies
ptrace(3C)						   Standard C Library Functions 						ptrace(3C)

NAME
ptrace - allows a parent process to control the execution of a child process SYNOPSIS
#include <unistd.h> #include <sys/types.h> int ptrace(int request, pid_t pid, int addr, int data); DESCRIPTION
The ptrace() function allows a parent process to control the execution of a child process. Its primary use is for the implementation of breakpoint debugging. The child process behaves normally until it encounters a signal (see signal.h(3HEAD)), at which time it enters a stopped state and its parent is notified by the wait(3C) function. When the child is in the stopped state, its parent can examine and mod- ify its "core image" using ptrace(). Also, the parent can cause the child either to terminate or continue, with the possibility of ignoring the signal that caused it to stop. The request argument determines the action to be taken by ptrace() and is one of the following: 0 This request must be issued by the child process if it is to be traced by its parent. It turns on the child's trace flag that stipulates that the child should be left in a stopped state on receipt of a signal rather than the state specified by func (see signal(3C)). The pid, addr, and data arguments are ignored, and a return value is not defined for this request. Peculiar results ensue if the parent does not expect to trace the child. The remainder of the requests can only be used by the parent process. For each, pid is the process ID of the child. The child must be in a stopped state before these requests are made. 1, 2 With these requests, the word at location addr in the address space of the child is returned to the parent process. If instruction and data space are separated, request 1 returns a word from instruction space, and request 2 returns a word from data space. If instruction and data space are not separated, either request 1 or request 2 may be used with equal results. The data argument is ignored. These two requests fail if addr is not the start address of a word, in which case -1 is returned to the parent process and the parent's errno is set to EIO. 3 With this request, the word at location addr in the child's user area in the system's address space (see <sys/user.h>) is returned to the parent process. The data argument is ignored. This request fails if addr is not the start address of a word or is outside the user area, in which case -1 is returned to the parent process and the parent's errno is set to EIO. 4, 5 With these requests, the value given by the data argument is written into the address space of the child at location addr. If instruction and data space are separated, request 4 writes a word into instruction space, and request 5 writes a word into data space. If instruction and data space are not separated, either request 4 or request 5 may be used with equal results. On success, the value written into the address space of the child is returned to the parent. These two requests fail if addr is not the start address of a word. On failure -1 is returned to the parent process and the parent's errno is set to EIO. 6 With this request, a few entries in the child's user area can be written. data gives the value that is to be written and addr is the location of the entry. The few entries that can be written are the general registers and the condition codes of the Processor Status Word. 7 This request causes the child to resume execution. If the data argument is 0, all pending signals including the one that caused the child to stop are canceled before it resumes execution. If the data argument is a valid signal number, the child resumes exe- cution as if it had incurred that signal, and any other pending signals are canceled. The addr argument must be equal to 1 for this request. On success, the value of data is returned to the parent. This request fails if data is not 0 or a valid signal num- ber, in which case -1 is returned to the parent process and the parent's errno is set to EIO. 8 This request causes the child to terminate with the same consequences as exit(2). 9 This request sets the trace bit in the Processor Status Word of the child and then executes the same steps as listed above for request 7. The trace bit causes an interrupt on completion of one machine instruction. This effectively allows single stepping of the child. To forestall possible fraud, ptrace() inhibits the set-user-ID facility on subsequent calls to one of the exec family of functions (see exec(2)). If a traced process calls one of these functions, it stops before executing the first instruction of the new image showing signal SIGTRAP. ERRORS
The ptrace() function will fail if: EIO The request argument is an illegal number. EPERM The calling process does not have appropriate privileges to control the calling process. See proc(4). ESRCH The pid argument identifies a child that does not exist or has not executed a ptrace() call with request 0. USAGE
The ptrace() function is available only with the 32-bit version of libc(3LIB). It is not available with the 64-bit version of this library. The /proc debugging interfaces should be used instead of ptrace(), which provides quite limited debugger support and is itself implemented using the /proc interfaces. There is no actual ptrace() system call in the kernel. See proc(4) for descriptions of the /proc debugging interfaces. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
exec(2), exit(2), libc(3LIB), signal(3C), signal.h(3HEAD), wait(3C), proc(4), attributes(5) SunOS 5.10 22 Mar 2004 ptrace(3C)
All times are GMT -4. The time now is 10:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy