views:

35

answers:

1

Hi everybody. I am trying to use Apple's example of using kqueue but the callback is never called unless I start observing the kqueue after the process starts. But the lifetime of the process is short and i need the code to work if the process starts before or after I start observing it.

A: 

What if you send the process a SIGSTOP immediately after starting it, and then SIGCONT after setting up the kqueue?

If you're using fork and exec directly, you could have the child send itself SIGSTOP (using raise(3)) and have the parent send it SIGCONT.

Peter Hosey
I don't understand how sending it SIGSTOP and SIGCONT would help since the kqueue only works if the process was started before the kqueue was set up.
Alex Zielenski
Your problem is that it exits too soon. If you can send it SIGSTOP before it exits, then you have all the time in the world to set up a kqueue.
Peter Hosey
Yeah, but the kqueue is already set up at that point. I'm not quite sure that you understand that it /does/ work if the process starts /before/ the kqueue does. And /does not/ work if the process is started /after/ I set up the kqueue
Alex Zielenski
Yes, I do understand that. If it only works if you start the process before setting up the kqueue, then your only option is to give yourself more time to set up the kqueue.
Peter Hosey
It seems that the SIGCONT and SIGSTOP isn't really an option for me. But what would be the reason behind the kqueue not working if i activate it before the process im observing begins? Is it a bug? Or what? Is it because theres no process id for it yet since it hasn't started? If so, am I able to specify an executable path?
Alex Zielenski
You can see in the example that you need the PID to tell `kevent` what process to watch. So, yes, you can only observe by PID. How are you creating the process? Can you show the code where you create the process and send it `SIGSTOP` and `SIGCONT`?
Peter Hosey
Alex Zielenski