4 ms·
imagine a program such as: print("hello") time.sleep(10) print("goodbye") If's impossible for the program to know which print is the last one, as
by mantap 6y ago
imagine a program such as:
print("hello")
time.sleep(10)
print("goodbye")
If's impossible for the program to know which print is the last one, as the user may kill the program during the sleep. I guess in a parallel universe you could have print issue a newline first. Not sure I want to live in that universe.
- hnlmorg 6y agoThe shell would know when the program has been finished for the same reason it knows when to print the shell prompt. The issue isn't that the shell is unaware of the state of the process, it's that the shell simply doesn't know where the cursor is nor what output a process has written to a TTY. And in fact a TTY can even be written to by processes outside of the same shell process group (since they're all just files in /dev).