Chet Ramey <chet.ra...@case.edu> writes: > On 9/5/22 6:13 PM, Aryan Bansal wrote: > > While testing how bash handles foreground and background processes > >using "&", I found out that the behaviour is sometimes undefined. The > >prompt sometimes prints just as the background process finishes executing > >resulting in a glitch that makes the prompt unable to be used until Enter > >is pressed. > > This is not a bug. Since these are different processes, scheduled > independently, bash doesn't have control of when the background processes > print their output.
In addition, the characters you input are handled asynchronously to both the process you background and foreground execution. You can "use the prompt" by typing whenever you want. The characters you type are queued up by the kernel and get read by whichever process tries to read the input first. In your case, only the foreground process will listen for input. Dale