I've been wondering this for some time, but irl just how does a signal know that a train has entered it's section of track in order to set itself to danger? I'm guessing there's electronics involved in the track. But then I get wondering about how that worked in the days of semaphore signals too. Surely the signalman doesn't have line of sight for the whole block?
These days yes. You may have heard talk of track circuits. No- sections could be miles long. One on the Settle-Carlisle was 11 miles IIRC and could cause long delays. Signal boxes would be sited where they had a good view of all the area they controlled if possible of course which is quite feasible if that's a station or junction or even part thereof. Between stations and junctions boxes would be where sections met so the signalman could see trains entering or leaving sections. The boxes were connected by a telegraph that sent bell codes and when a train passed your man would set the signal then contact the previous box to say the section was clear and the next box to say a train was on the way.
Surely, the signal doesn't "know" a thing ... It's just waiting for orders. They used to come from a human who pulled levers or ropes (I'm pretty sure); now they come from electrical impulses that are -- possibly -- more reliable than humans. Great! another wise-cracker answer from The Old Prof!!
For modern signalling there's usually either track circuits or axel counters to see whether there is a train in the signalling block. Even lots of traditional signal boxes in Britain are fitted with track circuits so that the signaller knows where the trains are, this can also help with safety as the track circuits can be interlocked with the signals so the signal cannot be cleared unless the section it protects is clear. In areas where there aren't any track circuits, the signalman won't be able to let a train into a section untill the train previously in it has passed the signalbox or has received confirmation from the next box along the line that the train is out of section by means of bell code, as JJTimothy said. This also means checking that a taillight is present on the rear of the train to ensure the train hasn't split and left some rolling stock on the line. This method of working is still present on some lines in Britain where the signalling hasn't been upgraded, though is gradually getting less and less common.
That's brilliant. Thanks everyone. I had forgotten the telegraph between boxes. Checking for the tail light is something I would never have realised how important that was. In modern signals, I'm guessing the circuits must be quite complex as it has to detect a train entering section, detect a train is completely out of section and detect the aspect of the signal ahead as well.
Take a look at https://www.railwaymuseum.org.uk/whats-on/signalling-demo Matt Peddlesden and a few others of us were lucky enough to get a private invitation to go there a year ago and spend the day being signalmen. It was very interesting stuff having to use the bells to signal to the other boxes that trains were coming and going. It has full interlocking so you have to do things in the right order. In normal times they do have public demonstrations most months but that is all on hold right now.