Notify when a process closes
Hi colleagues,
It is possible to know when any process is closed? When I refer to any process, is a process that is not a child of my application. I thought perhaps pipes in /proc/[pid]/fd/... could helpme, but really I have no idea how it could be. Any ideas, or is this possible? Best regards. |
Have you tried waitpid(PID_T, &status, 0) ?
edit - duh, waitpid is for children. A few ways you can do this. #1 - write a small "hook" application to be the parent. All it does is fork() + exec() and waitpid() #2 - ptrace() attach to the app, and let it continue executing. When it is delivered a signal, you can intercept. If it would exit() normally, your ptrace() call should fail with ESRCH. #3 - watch a pid file, or /proc/ filesystem. |
Thank you for your quick answer.
Quote:
Quote:
Code:
pid_t pid = 10000; Quote:
Thanks. |
Quote:
Quote:
|
Quote:
The way to read and write /proc is shown here: http://tldp.org/LDP/lkmpg/2.6/html/x769.html Code:
anisha@linux-uitj:~> ps -el Code:
anisha@linux-uitj:~> cd /proc |
Hi.
You can use GDB as a higher-level interface to ptrace() syscall. For example:
When `gvim' exits (you type :q) `script.sh' will be executed. Here is a test run Code:
$ gdb -batch -x eval-on-exit.gdb --quiet --pid=`pidof gvim` P.S. Following command allow gdb to attach to a running process without root priviledges (Ubuntu 10.10 and later): Code:
# echo 0 > /proc/sys/kernel/yama/ptrace_scope |
Well, this is an approximation of a possible solution to my question and thanks to their answer I can expose there here. This is the code where I put two variants of notification: through the 'sigaction' and through the 'waitpid' within the cycle.
Any comments or corrections are always welcome. Code:
|
All times are GMT -5. The time now is 11:18 PM. |