简体   繁体   English

C程序执行:它在进程还是线程中运行?

[英]C program execution: Does it run in a process or a thread?

I run a sample hello world program in C using Code Blocks. 我使用代码块在C中运行一个示例hello world程序。

When it executes it says the process returned 0 . 执行该命令时, the process returned 0

I know that it is run by the Operating system. 我知道它是由操作系统运行的。

I want to know a few things: 我想知道几件事:

  1. Is the program I executed associated with a separate process or the OS allocates a separate thread to it? 我执行的程序是否与单独的进程相关联,或者操作系统为其分配了单独的线程?

  2. When a function is called in Windows 32 bit or 64 bit, is the code segment register also pushed to stack? 在Windows 32位或64位中调用函数时,代码段寄存器是否也被压入堆栈?

The answer to your question depends upon how you view a process. 问题的答案取决于您如何看待流程。

IN the traditional process model where a process is a schedulable entity with an address space, you'd say that your program executed a process. 在传统的流程​​模型中,流程是具有地址空间的可调度实体,您会说程序执行了一个流程。

If you want to look at this traditional model as a process having a single thread, then your program ran in on thread. 如果您希望将这种传统模型视为具有单个线程的进程,则您的程序将在线程上运行。

It's just a word game. 这只是文字游戏。

If you're running on a system that schedules threads natively, then your program existed in a process that contained a thread where the execution took place. 如果在运行本机调度线程的系统上运行,则您的程序存在于一个包含执行线程的线程的进程中。

There are no segments in 64-bit. 没有64位段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM