An operating system (OS) manages hardware resources by controlling access to the central processing unit (CPU), memory, and input/output devices. It allocates memory to running programs and ensures that each program has access to the necessary resources. The OS also schedules tasks to be executed by the CPU, manages input and output operations, and provides a layer of abstraction between the hardware and software, allowing programs to interact with the hardware without needing to know the specific details of how it works. Additionally, the OS provides drivers that enable the hardware to communicate with the software.