How do programs execute?
来源:互联网 发布:淘宝玛卡是真的吗 编辑:程序博客网 时间:2024/05/20 04:29
Copied from: http://stackoverflow.com/questions/1599434/how-does-program-execute-where-does-the-operating-systems-come-into-play
For starters, a modern CPU has (at least) two modes, a mode in which it's running the core of the Operating System itself ("kernel mode") and a mode in which it's running programs ("user mode"). When in user mode, the CPU can't do a whole lot of things.
For instance, a mouse click is typically noticed in the kernel, not user mode. However, the OS dispatches the event to user mode and from there to the correct program. The other way around also requires cooperation: a program can't draw to the screen freely, but needs to go through the OS and kernel mode to draw on its part.
Similarly, the act of starting a program is typically a cooperation. The shell part of the OS is a user-mode program too. It gets your mouse click, and determines that it's a mouse click intended to start a process. The shell then tells the kernel-mode part of the OS to start a new process for that program.
When the kernel mode needs to start a new process, it first allocates memory for bookkeeping, and then proceeds to load the program. This involves retrieving the instructions from the binary, but also hooking up the program to the OS. This usually requires finding the entry point (classically int main(int argc, char** argv)
) of the binary, and all points where the program wants to call the OS.
Different Operating Systems use different ways to hook up programs with the OS. As a result, the loading process differs, and the file formats for binaries can differ too. It's not absolute; the ELF format for binaries is used for a number of Operating Systems, and Microsoft uses its PE format on all its current Operating Systems. In both cases, the format does describe the precise format of the binary, so the OS can decide whether the program can be hooked up to the OS. For instance, if it's a Win32 binary, if will be in the PE format. Linux wonn't load that; Windows 2000 will, as will Windows 7-64. A Win64 binary on the other hand is in PE format too, but Windows 2000 will reject it.
- How do programs execute?
- why do you need ./ to execute programs in current directory?
- How do I execute or run an XML file?
- How to Actually Execute Your To-do List
- How to Design Programs
- How to Debug Programs
- how do you do
- HOW Add/Remove Programs Works
- 《How to design programs》引子
- How Affiliate Software Programs Work
- How WinMain Execute
- How to execute Makefile
- How to Create Multi-Module Programs
- How to Create Multi-Module Programs
- How to design your first programs
- 《How to design programs》第一回
- 《How to design programs》第二回
- 《How to design programs》第三回
- HDU 4295 状态压缩dp + KMP
- 配置ehcache.xml -----02
- 分段函数
- 一个问题求解
- 匿名内部类的神奇用法——实现视图机制
- How do programs execute?
- 媒体播放器三大底层架构
- LoadRunner Java Vuser 脚本开发实例
- QuickTime 2002 错误小结
- 给走游戏程序员之路的初学者这参考心得
- POJ 1753 Flip Game【翻转棋盘+枚举+dfs】
- JDBC驱动下载汇总
- struts2.xml中使用chain和redirectAction这两个类型结果(type-result)时,报检查错误(validation)
- 我参加了2012IT博客大赛,欢迎投票