utrace and thread termination

Roland McGrath roland at redhat.com
Wed Nov 14 02:04:02 UTC 2007


Inside the kernel, you can use utrace for this.  At the moment, there is no
new canonical user-level interface that hooks into the utrace facilities.
So if you are looking for a replacement for ptrace in that sense, the
utrace layer per se does not fulfill that role by itself.

If you already have your own kernel code and a sufficient way for it to
communicate with user-level (e.g. whatever you use for monitor events),
then it is simple to use utrace in that kernel code to give a callback when
the thread is dying.  Since I imagine you already have your own per-thread
context in the kernel for perfmon and some hook by which to clean it up,
this may not be buying you anything at all.

Depending what you need, utrace too might be overkill.  It avoids many
important drawbacks of ptrace, but it does entail more complexity than
might be warranted for something really basic.  What utrace gives you is
synchronous notification, i.e. instant and with some possibility to
interlock with other bookkeeping before the process could be reaped (and
its PID reused if you don't have other get_task_struct refs on it).  If you
don't need that, there may be other options already in the upstream kernel.
For example, there is "connector", though AFAICT that only lets you ask for
all thread deaths across the whole system.  There might be some sort of
/proc polling or inotify or something that works (I haven't looked into that).


So, to answer your questions specifically:

> 	- does utrace offer this kind of notification directly?

Yes, in the sense that utrace itself is only an in-kernel API and therein
thread death notification is easy to arrange.  Call utrace_attach and then
utrace_set_flags with UTRACE_EVENT(DEATH) (or maybe EXIT, if you only care
about the end of user-mode activity), and then utrace_detach if you want to
clean up before it dies.  If it dies before you detach, it will call your
ops vector's report_detach callback.

> 	- if not, can this be built on top?

Yes, if what you meant was a user-level notification facility.  Right now
you'd be starting from scratch, or using someone's simple and raw prototype
based on utrace, or building your own onto some existing kernel<->user
communication mechanism.  Nothing has yet gotten anywhere near gelling as a
new canonical thing to be used for things that ptrace has been used for in
the past.  I hope this list is the place people will collaborate on
creating it.


Thanks,
Roland




More information about the utrace-devel mailing list