This forum is in archive mode. You will not be able to post new content.

Author Topic: [C] catch stderr of a process  (Read 1412 times)

0 Members and 1 Guest are viewing this topic.

Offline flowjob

  • Knight
  • **
  • Posts: 327
  • Cookies: 46
  • Pastafarian
    • View Profile
[C] catch stderr of a process
« on: May 21, 2012, 08:55:01 PM »
Ok,I'm quite new to C,and for fun and training I want to make something that catches stderr and prints it to the screen,but I don't know how I can attach to a process to be able to read it's stdin/stderr...

So my question is,how can I attach to a process and read its stderr in C?
Quote
<phil> I'm gonna DDOS the washing machine with clothes packets.
<deviant_sheep> dont use too much soap or youll cause a bubble overflow

Offline ca0s

  • VIP
  • Sir
  • *
  • Posts: 432
  • Cookies: 53
    • View Profile
    • ka0labs #
Re: [C] catch stderr of a process
« Reply #1 on: May 21, 2012, 08:56:51 PM »
Look for pipes.
I have not read it all, but I suppose you could do it like this
http://jineshkj.wordpress.com/2006/12/22/how-to-capture-stdin-stdout-and-stderr-of-child-program/
« Last Edit: May 21, 2012, 08:59:09 PM by ca0s »

Offline flowjob

  • Knight
  • **
  • Posts: 327
  • Cookies: 46
  • Pastafarian
    • View Profile
Re: [C] catch stderr of a process
« Reply #2 on: May 21, 2012, 09:08:56 PM »
It's quite helpful about the howto in general :) ,but doesn't really solves my problem,because...

1. I only want to catch stderr
2. I want to attach to a existing process instead of creating a new one...
« Last Edit: May 21, 2012, 09:28:10 PM by Area_13 »
Quote
<phil> I'm gonna DDOS the washing machine with clothes packets.
<deviant_sheep> dont use too much soap or youll cause a bubble overflow

Offline ca0s

  • VIP
  • Sir
  • *
  • Posts: 432
  • Cookies: 53
    • View Profile
    • ka0labs #
Re: [C] catch stderr of a process
« Reply #3 on: May 21, 2012, 09:25:03 PM »
Attaching is more complicated. Look for ptrace. Try to hook write() syscalls which have '2' as file descriptor.
http://www.linuxjournal.com/article/6100
You could also code a dynamic library and override write calls, using the LD_PRELOAD env. variable.
http://scaryreasoner.wordpress.com/2007/11/17/using-ld_preload-libraries-and-glibc-backtrace-function-for-debugging/
« Last Edit: May 21, 2012, 09:27:49 PM by ca0s »

Offline flowjob

  • Knight
  • **
  • Posts: 327
  • Cookies: 46
  • Pastafarian
    • View Profile
Re: [C] catch stderr of a process
« Reply #4 on: May 22, 2012, 07:04:25 PM »
So I've to do something like debugging the process I want to attach to?
« Last Edit: May 22, 2012, 07:11:34 PM by Area_13 »
Quote
<phil> I'm gonna DDOS the washing machine with clothes packets.
<deviant_sheep> dont use too much soap or youll cause a bubble overflow

 



Want to be here? Contact Ande, Factionwars or Kulverstukas on the forum or at IRC.