0

Imagine I'm developing a kind of system call which receives a pid_t pid and returns a file descriptor fd. What this syscall's got to do is monitor the process whose pid is pid so that, whenever this other process calls fork(), something is written to the file descriptor fd. To achieve this, I created a new list field in struct task_struct called, for example, files_to_signal_on_fork. So, my syscall creates a new struct file *file, gets the struct task_struct *task related to pid, add file to task's files_to_signal_on_fork list and returns the file descriptor representing file, so that I can use poll to keep track of when the other process calls fork(). I added a few lines of code to do_fork, so that, when it gets called, it writes something to all the struct file * structures stored in the process' files_to_signal_on_fork list.

So, is passing a process' struct file * structure to another process a good idea? Is there any way to check if the struct file *'s owner is still alive before do_fork try to write something to it?

4

1 回答 1

1

文件是引用计数的。删除最后一个引用时,您必须struct file从任务列表中删除 ( f_op->release)。

于 2013-07-01T07:50:14.027 回答