Write an indefinitely-running program that reports how many instances of itself are currently running. Each instance of the program should also report the order in which it was opened out of all other currently-running instances.
Example
The user launches the program for the first time - we'll call this Instance 1. Instance 1 displays 1/1
, because it is the first instance to be launched out of a total of 1 currently-running instances.
While Instance 1 is running, the user launches the program a second time to become Instance 2. Instance 1 now displays 1/2
, being the first instance out of a total of 2 currently-running instances. Instance 2 displays 2/2
, because it is the second instance out of a total of 2 currently-running instances.
Let's say the user continues to spawn more instances until there are 5 of them. In order of launch, their outputs are: 1/5
2/5
3/5
4/5
5/5
.
Now, let's say the user decides to terminate Instance 3. Instance 4 then becomes the new Instance 3 and Instance 5 the new Instance 4, because they are respectively the third and fourth instances to have been launched out of what is now a total of 4 instances. So each instance's change in output would be as follows:
1/5
→1/4
2/5
→2/4
3/5
→ (Terminated)4/5
→3/4
5/5
→4/4
Rules
- You may output the two numbers (instance number, total instances) in any reasonable format.
- Whenever an instance is launched or terminated, all other instances must update their respective outputs within 100 milliseconds.
- If you choose to update output by printing to a new line (or other "appending" output format; as opposed to replacement), you must print only when the number of instances changes, and not at any other time.
- This is code golf. Shortest program in bytes wins.
- In your answer, you are encouraged to specify what the user must do to open more than one instance, and/or record a screencast to demonstrate.