On 9/17/25 11:31 AM, pou...@tutamail.com wrote:
Chet Ramey wrote: > Why? If you're running the script from an interactive shell with job > control enabled, the standard input and standard output will be the > same as the parent shell.I am kicking myself why I had to be so easily provoked by some posts, as to rewrite the examples as two separate scripts. As originally posted, these are two functions that get called from within the same bash script. Nothing interactive in that. Now, if some other script, that calls my script, were to spin it off with an "&", that's when one of my functions gets stuck there forever. I am trying to find a way for my functions to detect such condition and avoid getting stuck.
There isn't a good way for a shell script to determine whether or not it's in the foreground or background, and whether it is in the same process group as the terminal. You could write a C/perl/python program that basically does tpgrp = tcgetpgrp(fd); mpgrp = getpgid(0); backgroud = tpgrp != mpgrp; and proceed accordingly, but if you try to read from the terminal or set the terminal attributes when you're not in the terminal's process group, your process is going to get stopped. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRU c...@case.edu http://tiswww.cwru.edu/~chet/
OpenPGP_signature.asc
Description: OpenPGP digital signature