title: See stdin/stdout/stderr of a running process - Linux kernel
body: <p>Is there a way to redirect/see the stdin/stdout/stderr of a given running process(By PID) in a simple way ?</p>
  
  <p>I tried the following (Assume that 'pid' contains a running user process):</p>
  
  <pre><code>int foo(const void* data, struct file* file, unsigned fd)
  {
      printf("Fd = %x\n", fd);
      return 0;
  }
  struct task_struct* task = pid_task(find_vpid(pid), PIDTYPE_PID);
  struct files_struct* fs = task-&gt;files;
  iterate_fd(fs, 0, foo, NULL);
  </code></pre>
  
  <p>I get 3 calls to foo (This process probably has 3 opened files, makes sense) but I can't really read from them (from the file pointers).</p>
  
  <p>It prints:</p>
  
  <pre><code>0
  1
  2
  </code></pre>
  
  <p>Is it possible to achieve what I asked for in a fairly simple way ?</p>
  
  <p>thanks</p>