0

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.

Alex Zielenski
  • 3,591
  • 1
  • 26
  • 44

1 Answers1

0

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
  • 95,783
  • 15
  • 211
  • 370
  • 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 Jul 07 '10 at 01:05
  • 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 Jul 07 '10 at 04:48
  • 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 Jul 07 '10 at 11:48
  • 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 Jul 07 '10 at 18:01
  • 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 Jul 07 '10 at 21:14
  • 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 Jul 07 '10 at 22:01
  • I'm not sending it SIGSTOP or SIGCONT. It's not an option for me because I need it to be fast & instant. But i found a way to do this. If the process isn't started while the start method is being called, I set up a process polling class I made and get a notification of when the process launches, and that is when i start the kqueue – Alex Zielenski Jul 07 '10 at 23:55