的操作系统里面的工作吗

的操作系统里面的工作吗

本文介绍了如何scanf()的操作系统里面的工作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在想如何scanf()的/ printf()的实际工作中的硬件和操作系统层。哪里的数据流和到底是什么操作系统围绕这些时间做什么?什么叫没有操作系统做什么呢?等等...

I've been wondering how scanf()/printf() actually works in the hardware and OS levels. Where does the data flow and what exactly is the OS doing around these times? What calls does the OS make? And so on...

推荐答案

scanf函数()和printf()是在libc中(C标准库)功能,以及它们调用read()和write()操作系统分别为系统调用,谈话的文件描述符分别stdin和stdout(的fscanf和fprintf允许您指定要读/写文件流)。

scanf() and printf() are functions in libc (the C standard library), and they call the read() and write() operating system syscalls respectively, talking to the file descriptors stdin and stdout respectively (fscanf and fprintf allow you to specify the file stream you want to read/write from).

调用阅读()和write()(和所有的系统调用)导致上下文切换出你的用户级应用到内核模式,这意味着它可以执行特权操作,如直接对话的硬件。这取决于你如何启动应用程序时,标准输入和标准输出文件描述符可能绑定到一个控制台设备(如tty0的),或某种虚拟控制台设备(如通过的xterm曝光)。阅读()和write()中的数据安全地复制到/从内核缓冲区称为UIO。

Calls to read() and write() (and all syscalls) result in a 'context switch' out of your user-level application into kernel mode, which means it can perform privileged operations, such as talking directly to hardware. Depending on how you started the application, the 'stdin' and 'stdout' file descriptors are probably bound to a console device (such as tty0), or some sort of virtual console device (like that exposed by an xterm). read() and write() safely copy the data to/from a kernel buffer called a 'uio'.

scanf函数和printf的格式字符串转换部分不会发生在内核模式下,只是在普通用户模式(内'的libc),与系统调用一般的经验法则是你切换到内核模式尽可能少,既避免了上下文切换的性能开销,并为安全性(你必须非常小心发生的任何事情在内核模式!少code在内核模式中的操作系统意味着更少的错误/安全漏洞)。

The format-string conversion part of scanf and printf does not occur in kernel mode, but just in ordinary user mode (inside 'libc'), the general rule of thumb with syscalls is you switch to kernel mode as infrequently as possible, both to avoid the performance overhead of context switching, and for security (you need to be very careful about anything that happens in kernel mode! less code in kernel mode means less bugs/security holes in the operating system).

顺便说一句..这一切从UNIX的角度写的,我不知道微软Windows是如何工作的。

btw.. all of this was written from a unix perspective, I don't know how MS Windows works.

这篇关于如何scanf()的操作系统里面的工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 16:54