# use of C library in operating systems [closed]

I wonder, how is that operating systems make use of libraries as stdio.h if they themselves are the services? I am right? Is the operating system that interacts with the hardware to operations of I/O? How you write to a file system with the C library, for example?

## closed as off-topic by Luke Mathieson, vonbrand, Ran G., Evil, Thomas KlimpelOct 22 '15 at 7:31

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question does not appear to be about computer science, within the scope defined in the help center." – Luke Mathieson, Evil, Thomas Klimpel
If this question can be reworded to fit the rules in the help center, please edit the question.

• This Exchange Site is for Computer Science questions, please ask questions that are on-topic for this site. – Spencer Wieczorek Oct 13 '15 at 4:49
• @SpencerWieczorek I think the question is close enough to being on-topic, since it doesn't seem very important that it's the C library rather than any other language. How libraries and operating systems interact in general is on-topic, I think. – David Richerby Oct 13 '15 at 7:20
• Yes, it's the OS that interacts with hardware to do IO. But I can't work out what the rest of your question is asking. Could you try to expand it and make it clearer? – David Richerby Oct 13 '15 at 7:22

The kernel does offer system calls like read(3) and write(3) in Unix, and translates them into whatever magic the underlying hardware requires to do this. For example, as a very rough description of how this goes, to write to a serial port, the kernel copies the individual bytes to the serial port's register, signals that a new character is ready to transmit, and waits for it to be shipped off before placing the next one there. To write into a file the kernel keeps track of where the writing to the file has to take place, asks for space in the underlying device if the file will grow, and writes into the allocated space. Each filessystem has its own (rather complex) data structures on disk and in memory to keep track of free and allocated space, and so on. To manipulate it (and the underlying blocks on disk) usually another complex layer talking to the hardware is interposed.
The kernel does write messages on occasion. For this it has internal functions (in the case of e.g. Linux it is printk that mimics printf(3)) to do this by tickling the underlying hardware the right way.