
windows编程中句柄是可继承的是什么意思? 60
比如SECURITY_ATTRIBUTESsa={sizeof(sa)};sa.bInheritHandle=TRUE;sa.lpSecurityDescriptor=N...
比如
SECURITY_ATTRIBUTES sa = {sizeof(sa)};
sa.bInheritHandle = TRUE;
sa.lpSecurityDescriptor = NULL;
hThread = CreateThread(&sa,NULL,ThreadTest,NULL,0,&dwThreadID);
这样创建的线程句柄和
hThread = CreateThread(NULL,NULL,ThreadTest,NULL,0,&dwThreadID);
这样创建的线程句柄有什么区别? 展开
SECURITY_ATTRIBUTES sa = {sizeof(sa)};
sa.bInheritHandle = TRUE;
sa.lpSecurityDescriptor = NULL;
hThread = CreateThread(&sa,NULL,ThreadTest,NULL,0,&dwThreadID);
这样创建的线程句柄和
hThread = CreateThread(NULL,NULL,ThreadTest,NULL,0,&dwThreadID);
这样创建的线程句柄有什么区别? 展开
3个回答
展开全部
例如:hThread = CreateThread(NULL,NULL,ThreadTest,NULL,0,&dwThreadID);
这种是用线程内核对象的默认安全属性,子进程是不可以继承这个内核对象句柄的。
注意这里说的可继承,是指的是父进程生成子进程的时候才发生。
也就是说如果,是可以继承的,指的是这个内核对象句柄是可以被子进程访问的。
不可以继承,则子进程是不可以通过句柄访问改内核对象。
SECURITY_ATTRIBUTES sa = {sizeof(sa)};
sa.bInheritHandle = TRUE;
sa.lpSecurityDescriptor = NULL;
hThread = CreateThread(&sa,NULL,ThreadTest,NULL,0,&dwThreadID);
这种写法就是可以继承的。
你可以这样理解
父进程有个句柄表,这个表记录了可以访问线程内核对象的句柄。
如果这个句柄可以继承。
则父进程创建的子进程,这个子进程的句柄表中,也有记录了访问线程内核对象的句柄,和父进程的句柄表中一样。
不可以继承的话,则子进程表中是不可以访问的。
补充:句柄是一个让你操纵某个对象的标识符。在windows中句柄有很多类型,有的是指针,有的是指向指针的指针,有的是一个数组索引。
但在编程中不需要在乎句柄是怎么样的,因为winapi调用掩盖了句柄操作的细节。
这种是用线程内核对象的默认安全属性,子进程是不可以继承这个内核对象句柄的。
注意这里说的可继承,是指的是父进程生成子进程的时候才发生。
也就是说如果,是可以继承的,指的是这个内核对象句柄是可以被子进程访问的。
不可以继承,则子进程是不可以通过句柄访问改内核对象。
SECURITY_ATTRIBUTES sa = {sizeof(sa)};
sa.bInheritHandle = TRUE;
sa.lpSecurityDescriptor = NULL;
hThread = CreateThread(&sa,NULL,ThreadTest,NULL,0,&dwThreadID);
这种写法就是可以继承的。
你可以这样理解
父进程有个句柄表,这个表记录了可以访问线程内核对象的句柄。
如果这个句柄可以继承。
则父进程创建的子进程,这个子进程的句柄表中,也有记录了访问线程内核对象的句柄,和父进程的句柄表中一样。
不可以继承的话,则子进程表中是不可以访问的。
补充:句柄是一个让你操纵某个对象的标识符。在windows中句柄有很多类型,有的是指针,有的是指向指针的指针,有的是一个数组索引。
但在编程中不需要在乎句柄是怎么样的,因为winapi调用掩盖了句柄操作的细节。
展开全部
hThread = CreateThread(NULL,NULL,ThreadTest,NULL,0,&dwThreadID);
这种是用线程内核对象的默认安全属性,子进程是不可以继承这个内核对象句柄的。
注意这里说的可继承,是指的是父进程生成子进程的时候才发生。
也就是说如果,是可以继承的,指的是这个内核对象句柄是可以被子进程访问的。
不可以继承,则子进程是不可以通过句柄访问改内核对象。
SECURITY_ATTRIBUTES sa = {sizeof(sa)};
sa.bInheritHandle = TRUE;
sa.lpSecurityDescriptor = NULL;
hThread = CreateThread(&sa,NULL,ThreadTest,NULL,0,&dwThreadID);
这种写法就是可以继承的。
你可以这样理解
父进程有个句柄表,这个表记录了可以访问线程内核对象的句柄。
如果这个句柄可以继承。
则父进程创建的子进程,这个子进程的句柄表中,也有记录了访问线程内核对象的句柄,和父进程的句柄表中一样。
不可以继承的话,则子进程表中是不可以访问的。
这种是用线程内核对象的默认安全属性,子进程是不可以继承这个内核对象句柄的。
注意这里说的可继承,是指的是父进程生成子进程的时候才发生。
也就是说如果,是可以继承的,指的是这个内核对象句柄是可以被子进程访问的。
不可以继承,则子进程是不可以通过句柄访问改内核对象。
SECURITY_ATTRIBUTES sa = {sizeof(sa)};
sa.bInheritHandle = TRUE;
sa.lpSecurityDescriptor = NULL;
hThread = CreateThread(&sa,NULL,ThreadTest,NULL,0,&dwThreadID);
这种写法就是可以继承的。
你可以这样理解
父进程有个句柄表,这个表记录了可以访问线程内核对象的句柄。
如果这个句柄可以继承。
则父进程创建的子进程,这个子进程的句柄表中,也有记录了访问线程内核对象的句柄,和父进程的句柄表中一样。
不可以继承的话,则子进程表中是不可以访问的。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2012-09-24
展开全部
I am also confused by this problem. I search for lots of data. There is some that might help:
The member for length of the SECURITY_ATTRIBUTES is DWORD nLength which describes the length of the struct in bytes. So you are supposed to set this value to the size of the SECURITY_ATTRIBUTES structure. A pointer to a security descriptor for the object that controls the sharing of it. If NULL is specified for this member, the object is assigned the default security descriptor of the calling process. This is not the same as granting access to everyone by assigning a NULL discretionary access control list (DACL). The default security descriptor is based on the default DACL of the access token belonging to the calling process. By default, the default DACL in the access token of a process allows access only to the user represented by the access token. If other users must access the object, you can either create a security descriptor with the appropriate access, or add ACEs to the DACL that grants access to a group of users. If lpSecurityAttributes is NULL, the handle cannot be inherited.
So when the first parameter is set as NULL, it means the returned handle will not be inherited.
While when it is set as &sa, the member bInheritHandle will determine whether the returned handle inherited or not.
Hope this might help.
The member for length of the SECURITY_ATTRIBUTES is DWORD nLength which describes the length of the struct in bytes. So you are supposed to set this value to the size of the SECURITY_ATTRIBUTES structure. A pointer to a security descriptor for the object that controls the sharing of it. If NULL is specified for this member, the object is assigned the default security descriptor of the calling process. This is not the same as granting access to everyone by assigning a NULL discretionary access control list (DACL). The default security descriptor is based on the default DACL of the access token belonging to the calling process. By default, the default DACL in the access token of a process allows access only to the user represented by the access token. If other users must access the object, you can either create a security descriptor with the appropriate access, or add ACEs to the DACL that grants access to a group of users. If lpSecurityAttributes is NULL, the handle cannot be inherited.
So when the first parameter is set as NULL, it means the returned handle will not be inherited.
While when it is set as &sa, the member bInheritHandle will determine whether the returned handle inherited or not.
Hope this might help.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询