A student in my course is looking for a way to launch processes simultaneously on multiple raspberry pi computers. It was not immediately apparent to me how to do this, but the first thing that came to mind was "at" which lets you schedule a process to launch "at" a particular time. To test, I set up two rasberry pis: mahiro and poneo.
I wrote a python script:
----now.py----#! /usr/bin/python3
import time
ns = time.time_ns()
timestamp = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(f'"{timestamp}",{ns}')
file = open("/home/pi/attest/time.txt","a")
file.write(f'"{timestamp}",{ns}\n')
file.close()
a shell script to invoke it:
----now.sh----#! /bin/sh
/usr/bin/python3 /home/pi/attest/now.py
I put that on two pis, made sure the timezone was set to eastern, then used a script on my laptop to invoke it:
----attest.sh----#! /bin/bash
ssh pi@mahiro at -f /home/pi/attest/now.sh "$1 today"
ssh pi@poneo at -f /home/pi/attest/now.sh "$1 today"
So, this uses ssh to talk to the pis and runs the "at" command to run the bash script at a particular time today. Then I tell the script what time to run, e.g../attest.sh 10:30am
And then the script invokes the processes on the same second on both pis. Here are the results:----poneo----
"2020-11-10 10:22:00",1605021720479176213
"2020-11-10 10:29:00",1605022140756637058
"2020-11-10 10:30:01",1605022201055563711
"2020-11-10 10:31:00",1605022260561006216
----mahiro----
"2020-11-10 10:22:00",1605021720479176213
"2020-11-10 10:29:00",1605022140295769154
"2020-11-10 10:30:00",1605022200649709852
"2020-11-10 10:31:00",1605022260111136737
The first time, it worked PERFECTLY -- the nanosecond time readings are identical. In the other ones, they're not even always within the same second. But pretty close.
So, now we need to decide whether this is close enough or if we need to find another approach.
- Steven D. Brewer's blog
- Log in to post comments