Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!ut-sally!husc6!cmcl2!brl-adm!adm!kvancamp@ARDEC.arpa From: kvancamp@ARDEC.arpa (Kenneth Van Camp -FSAC-) Newsgroups: comp.unix.questions Subject: bg process into fg Message-ID: <7338@brl-adm.ARPA> Date: Tue, 12-May-87 14:41:59 EDT Article-I.D.: brl-adm.7338 Posted: Tue May 12 14:41:59 1987 Date-Received: Fri, 15-May-87 02:23:33 EDT Sender: news@brl-adm.ARPA Lines: 68 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 #include 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 first * 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; } --Ken Van Camp Army Armament Research Development & Engineering Center SMCAR-FSA-E Building 329 Dover, NJ 07806-5000 (201)724-3334 (AV)880-3334