The operating system is responsible for allocating memory to a program, and ensuring that different programs stay within their lane. If a program attempts to write memory outside of its allocated range, the OS detects this as a segmentation fault and kills the program with the message segmentation fault (core dumped).