Click to See Complete Forum and Search --> : end of process


spizkapa
06-13-2003, 10:02 AM
Hi all,

I was wondering if anyone knows of a good way to let the user know that a process has finished. In particular, I program in C exclusively and I'd like to know when a process of mine has terminated (gracefully) so that I can check the results that it's produced.

One of the ways I've found is to print the bell character on the command line so that the process "beeps" before it dies. the problem is that I hardly ever hear it even if it beeps for a while...

Another way is to use something simple like emailing myself at the end of process but emails can also take some time to arrive.

Any ideas?

binaryDigit
06-13-2003, 10:26 AM
you could fork the process at the end and run another program.
you could have it run xmms and play a certain song :D

terribleRobbo
06-13-2003, 11:14 AM
Have it chuck to stdout the different stages it's going through, as well as a "Finished." line.

Include a -q or --quiet flag to turn it off.

Failing that, have it chuck to stderr instead, if it needs to ouput meaningful data to stdout.

spizkapa
06-13-2003, 11:25 AM
I think that (with a bit of googling) I have now found a decent way of doing it.

You need to #include <time.h>

and then put the following code at the end of your process:

--------------------------------------------------------
time(&aclock );
newtime = localtime( &aclock );

sprintf(str, "xmessage \"Process terminated at %s\"", asctime(newtime));

system(str);
--------------------------------------------------------

Now, at the end of the process, a window pops up at the desktop that was active at the time (so you can check the justlinux forums while your program chunks numbers) and tells you that the process terminated at a specific time.

The coolest thing about it is that it adds nothing to the size of the executable (which would be the case if you used -say- a GTK window) since the X libraries are already active!


spizkapa

bwkaz
06-13-2003, 06:53 PM
Umm... better idea.

In the program that calls your program, implement a SIGCHLD handler that does what you want. Relatively simple, and it won't fail. :)

Unless you're running your program from the shell -- you can't replace the shell's SIGCHLD handler (and you wouldn't want to). But if you're running it from a shell, do yourprogramname yourprogramargs && beep to beep after yourprogramname exits.