首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

退出代码是什么概念?该如何解决

2012-08-26 
退出代码是什么概念?进程,线程的推出代码是什么概念啊?书上只提到.谁能详细的说说啊,[解决办法]The ExitPr

退出代码是什么概念?
进程,线程的推出代码是什么概念啊?书上只提到.谁能详细的说说啊,

[解决办法]
The ExitProcess function ends a process and all its threads. 

VOID ExitProcess(
UINT uExitCode // exit code for all threads
);
 
Parameters
uExitCode 
Specifies the exit code for the process, and for all threads that are terminated as a result of this call. Use the GetExitCodeProcess function to retrieve the process's exit value. Use the GetExitCodeThread function to retrieve a thread's exit value. 
Return Values
This function does not return a value. 

Remarks
ExitProcess is the preferred method of ending a process. This function provides a clean process shutdown. This includes calling the entry-point function of all attached dynamic-link libraries (DLLs) with a value indicating that the process is detaching from the DLL. If a process terminates by calling TerminateProcess, the DLLs that the process is attached to are not notified of the process termination. 

After all attached DLLs have executed any process termination value, this function terminates the current process. 

Terminating a process causes the following: 

All of the object handles opened by the process are closed. 
All of the threads in the process terminate their execution. 
The state of the process object becomes signaled, satisfying any threads that had been waiting for the process to terminate. 
The states of all threads of the process become signaled, satisfying any threads that had been waiting for the threads to terminate. 
The termination status of the process changes from STILL_ACTIVE to the exit value of the process. 
Terminating a process does not cause child processes to be terminated. 

Terminating a process does not necessarily remove the process object from the operating system. A process object is deleted when the last handle to the process is closed. 

The ExitProcess, ExitThread, CreateThread, CreateRemoteThread functions, and a process that is starting (as the result of a call by CreateProcess) are serialized between each other within a process. Only one of these events can happen in an address space at a time. This means the following restrictions hold: 

During process startup and DLL initialization routines, new threads can be created, but they do not begin execution until DLL initialization is done for the process. 
Only one thread in a process can be in a DLL initialization or detach routine at a time. 
ExitProcess does not return until no threads are in their DLL initialization or detach routines. 

[解决办法]
学习了...
[解决办法]
2楼已经正解了。
我补充一下:退出代码往往用于表达线程是否安全退出、或异常退出、或不正常退出(但在预期范围之内)。
通过获取退出代码,可以知道该线程的任务是否完成!
如果没有完成,再...
[解决办法]

探讨
不知道这段代码能不能进入windows多线程里面,就连核心编程第5版也没这个实例.

[解决办法]
估计你所说的退出代码是一个进程或者线程结束时返回给创建方的一个值。进程的退出代码由进程的main函数的return语句或者调用exit函数时指定,由它的父进程用wait函数来取得。线程的退出代码由线程的pthread_exit函数来指定,由别的线程(一般是创建它的那个线程)用pthread_join函数来取得。
[解决办法]
引用楼主 appleshao 的帖子:
进程,线程的推出代码是什么概念啊?书上只提到.谁能详细的说说啊,

[解决办法]
>进程,线程的推出代码是什么概念啊?书上只提到.谁能详细的说说啊,
apue中提到,线程如果从启动例程返回,返回值是线程的退出码。还有其它两种退出方式是被同一进程的其它线程取消、线程直接调用
pthread_exit。如果线程只是从它的启动例程中返回pthread_exit的无类型参数rval_ptr可以获得退出码。利用pthread_join可以获取线程退出状态,在没有线程退出时,调用这个函数的线程会被堵塞。


函数原型为:

C/C++ code
#include <pthread.h>void pthread_exit(void *rval_ptr);int pthread_join(pthread_t thread,void **rval_ptr);
[解决办法]
探讨
搞了半天是怎么一回事,所谓的退出代码其实就是一个进程的或者一个线程的return语句.....
算了不想批评谁了,这是我自己测试的代码希望路过的人能看到.

C/C++ code
#include <windows.h>
#include <stdio.h>
DWORD dwExitCode;

int main(int argc, char* argv[])
{
char szCommandLine[] = "C:\\Users\\Administrator\\Desktop\\fjc.exe"; //注意Unicode字节;vs2005系列的要设置成双字节字符集
STARTUPINFO…

[解决办法]
探讨
搞了半天是怎么一回事,所谓的退出代码其实就是一个进程的或者一个线程的return语句.....
算了不想批评谁了,这是我自己测试的代码希望路过的人能看到.
C/C++ code

#include <windows.h>
#include <stdio.h>
DWORD dwExitCode;

int main(int argc, char* argv[])
{
char szCommandLine[] = "C:\\Users\\Administrator\\Desktop\\fjc.exe"; //注意Unicode字节;vs2005系列的要设置成双字节字符集
STARTUPINFO si = { siz…

热点排行