The device that lets a surfaced or shallow-running submarine receive air from above while keeping its diesel engines operating is a snorkel. It is a retractable mast containing an air-intake pipe and usually an exhaust arrangement.
Diesel-electric submarines need atmospheric oxygen for their diesel engines. Before snorkels became common, a submarine had to surface to run its engines and recharge batteries, exposing it to visual and radar detection. A snorkel allowed the boat to remain mostly submerged while performing those tasks.
The system was developed and used extensively by Germany during the Second World War, especially in late-war Type XXI and Type XXIII submarines. Snorkeling still created hazards: waves could close the intake valve, and engine operation made the submarine noisier.
A snorkel is not a periscope. A periscope is primarily an optical observation instrument, while a snorkel supports propulsion and battery charging.