1748136 Members
3746 Online
108758 Solutions
New Discussion

Re: Modify script

 
Intothenewworld
Advisor

Modify script

in my linux system , we have a program ( it is a binary program , I do not have the source code ) which will do something in the database . In the program , there is a exit function , when select exit , it will quit the program and go to linux shell , this program works fine.

Now , I would like to do modify for this program -- I would like to send out a mail to me once quitted this program , but how to know (detect) the program is quitted ?

thx


** may be my question is not clear enough , I will reply it if anything is not clear.

2 REPLIES 2
Dennis Handly
Acclaimed Contributor

Re: Modify script

(This is a HP-UX board, not Linux.)

 

>I would like to do modify for this program

 

You can't, you don't have the source.  You could modify the script.

 

>I would like to send out a mail to me once quitted this program but how to know (detect) the program is quitted?

 

All you can know is the exit status, $? for a real shell.

H.Becker
Honored Contributor

Re: Modify script

You can try to pre-load a shared library which registers an atexit routine, just like:

 

$ cat hello.c
#include <stdio.h>
#include <stdlib.h>
int main (void) {
        printf ("%s, hello\n", __func__);
        exit (EXIT_SUCCESS);
}
$ make hello
cc     hello.c   -o hello
$ ./hello
main, hello
$
$ cat addatexit.c 
#include <stdio.h>
void myexit(void) {
        printf ("%s, here we are\n",__func__);
}
static void __attribute__((constructor)) init() {
        atexit(myexit);
}
$ cc -o addatexit -shared addatexit.c
$ LD_PRELOAD=./addatexit ./hello
main, hello
myexit, here we are
$