创建独立的流程! [英] Creating independent process!

查看:66
本文介绍了创建独立的流程!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用C ++中的服务创建一个进程.这个新过程正在创建为子过程.我想创建一个独立的进程而不是一个子进程...

I am trying to create a process from a service in C++. This new process is creating as a child process. I want to create an independent process and not a child process...

我正在使用CreateProcess函数.由于我创建的新进程是子进程,因此当我尝试在服务级别终止进程树时,它也正在终止子进程……我不希望这种情况发生.我希望创建的新进程独立于服务运行.

I am using CreateProcess function for the same. Since the new process i create is a child process when i try to kill process tree at the service level it is killing the child process too... I dont want this to happen. I want the new process created to run independent of the service.

请在同一点上提出建议.谢谢.

Please advice on the same.. Thanks..

代码

STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);    // Start the child process.
ZeroMemory( &pi, sizeof(pi) );
si.dwFlags = STARTF_USESHOWWINDOW;

if(bRunOnWinLogonDesktop)
{
    if(csDesktopName.empty())
        si.lpDesktop = _T("winsta0\\default");
    else
        _tcscpy(si.lpDesktop, csDesktopName.c_str());
}

if(bHide)
    si.wShowWindow = SW_HIDE;     /* maybe even SW_HIDE */
else
    si.wShowWindow = SW_SHOW;     /* maybe even SW_HIDE */



TCHAR szCmdLine[512];
_tcscpy(szCmdLine, csCmdLine.c_str());

if( !CreateProcess( NULL,
                szCmdLine,
               NULL,
               NULL,
               FALSE,
               CREATE_NEW_PROCESS_GROUP,
               NULL,        
               NULL,        
               &si,        
               &pi ) ) 

推荐答案

在关闭子进程的线程和进程处理程序之后,它仍然是Process Explorer中的一个子进程,但是结束父进程不会导致终止该子进程

After closing thread and process handlers of the child process, it's still a child in the Process Explorer, but ending parent process doesn't cause termination of the child one.

CreateProcess( NULL,
            szCmdLine,
           NULL,
           NULL,
           FALSE,
           CREATE_NEW_PROCESS_GROUP,
           NULL,        
           NULL,        
           &si,        
           &pi ); 
if(pi.hThread)
    CloseHandle(pi.hTread);
if(pi.hProcess)
    CloseHandle(pi.hProcess);

我在 ReactOS 的="nofollow"> cmd.exe的来源.执行启动"命令的过程.

I've found this decision in sources of cmd.exe of the ReactOS, in the procedure of executing 'start' command.

这篇关于创建独立的流程!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆