有没有简单的方法来重定向/查看正在运行的进程(按PID)的stdin/stdout/stderr?
我尝试了以下方法(假设'pid'包含一个运行中的用户进程):
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->files;
iterate_fd(fs, 0, foo, NULL);
我收到了3个foo的调用(这个进程可能有3个打开的文件,这很合理),但我实际上无法从它们(从文件指针)中读取。
它会打印:
0
1
2
有没有比较简单的方法可以实现我所要求的内容呢?
谢谢。