I have an executable module created by third party. I would like to "inject" my code (kind of watchdog running in separate thread) into this process.
So far there are two possible ways - one is to run my code as executable and dynamically load a proess on top of it (seems to be very hard and tricky) or to make my code a shared object, load it via LD_PRELOAD and initialize from some static variable constructor.
Are there more convenient ways to do this ? My OS are Linux x86 and Solaris-SPARC.
Update: If possible, I'd like not to patch the process, but load my code dynamicaly.