Is there a way to get a background process into the foreground in System V?
I know about C-shell's 'fg' command, but this won't work because (1) our
Silicon Graphics System V system doesn't support this aspect of the C-shell,
and (2) the process needs to be brought into the foreground after being
created from a different shell (i.e., I need to logout after creating the
background process).
Here's the problem: I have a C program (and all the source code, so
I can consider C solutions as well as shell solutions) that does alot of
number crunching. Typical runs take several hours, and sometimes as long as
a day. Since I can't tie up my terminal during all that time, it naturally
has to be run in the background. At this time I may logout. However,
during the middle of a long run I would like to log back in and
interrogate/modify the run. To do this, I have set up signal interrupts
(available via the normal Kill command) to alert the program that I wish to
interrogate the model. Doing normal printf stuff, I never see the output on
my terminal because the process is background. I need a way to bring it
into the foreground so I can interact with it.
Alternatively, I can just write to the tty device directly. I tried
this, and it worked for output but not for input. Here's an example, which
always reports num=0 and does not wait for user response. I'd appreciate
any suggestions.
/* testbg.c: test writing/reading from background process */
#include <stdio.h>
#include <sys/signal.h>
int useio = 0;
main()
{
FILE *filout, *filin, *fopen();
int (*s16_svc())();
int num;
signal (SIGUSR1, s16_svc);
while(1)
if (useio){
filout = fopen ("/dev/console", "w");
filin = fopen ("/dev/console", "r");
fprintf (filout,"Enter a number:\n");
fscanf (filin, &num);
fprintf (filout,"Read number %d\n", num);
fclose (filout);
fclose (filin);
useio = 0;
}
/* s16_svc: signal 16 service routine. Sets the global useio flag the firstQuote:}
* five times it is called; the sixth time it stops the program.
*/
int (*s16_svc (sig))()
int sig;
{
static int count = 0;
if (++count > 5)
exit(0);
/* reset the signal so it works again */
signal (SIGUSR1, s16_svc);
/* set the global flag to use the i/o */
useio = 1;
Quote:}
Army Armament Research Development & Engineering Center
SMCAR-FSA-E Building 329
Dover, NJ 07806-5000
(201)724-3334 (AV)880-3334