0

Considering the situation, there are three files: run.sh, test1.py, test2.py

python3 test1.py

test1.py

import time
if __name__ == '__main__':
    print("the first hello from test1.py")
    time.sleep(20)
    print("the second hello from test1.py")

test2.py

import time
if __name__ == '__main__':
    print("hello from test2.py")

if I type this bash run.sh in the command line and execute it. When the file is executed time.sleep () command, I changed it run.sh file and add a line python test2.py.

In this situation, how the bash interpreter work? My test shows that the console will output three lines, could you please tell me the principle?

  • 1
    When you have two programs, one program reads one line from file, the other adds a line to file, will the first program read another line or not? – KamilCuk Jan 12 '21 at 10:01
  • I think it depends on whether the interpreter reads all at once or reads by line – harvey huang Jan 12 '21 at 11:22
  • Sure it depends. It also depends on buffering, both on kernel side and on userspace side. But it's exactly the same situation as two programs, one reading another writing, to the same file at the same time, with no locking or synchronization. – KamilCuk Jan 12 '21 at 11:47
  • Sure, this is about synchronization. So I want to know how the bash interpreter deals with it. – harvey huang Jan 13 '21 at 04:37

0 Answers0