Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9018313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:29:38+00:00 2026-06-16T04:29:38+00:00

With processes, I can do the following: int pid; ::CreateProcess(NULL, cmd, …, &pi); pid

  • 0

With processes, I can do the following:

int pid;
::CreateProcess(NULL, cmd, ..., &pi);
pid = pi.dwProcessId;
::CloseHandle(pi.hProcess);
// then later...
HANDLE proc = ::OpenProcess(PROCESS_TERMINATE, FALSE, pid);
::TerminateProcess(proc, 1);
::CloseHandle(proc);

In this fashion, I can manage windows processes by pid only, which is nice for multi-platform code.

I would like to extend this pattern to job objects:

HANDLE job = ::CreateJobObject(NULL, name);
::AssignProcessToJobObject(job, proc); // proc from above
::CloseHandle(job);
// then later...
job = ::OpenJobObject(JOB_OBJECT_TERMINATE, FALSE, name);
::TerminateJobObject(job, 1);

To be clear, I am not in the job, but my child process is. MSDN says “The job is destroyed when its last handle has been closed and all associated processes have exited”. In this case, my main process has closed his last handle, but the child is still running, and still has a handle. A call to IsProcessInJob(proc, NULL, &isit) confirms the job still exists. However, my call to open the job returns NULL, and the error code is ERROR_FILE_NOT_FOUND.

So the question: does my main process have any way to get a handle to the job after closing it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T04:29:39+00:00Added an answer on June 16, 2026 at 4:29 am

    Yes, it is possible. However, observe:

    // This example will fail to reopen and terminate the job.
    // Processes cmd and ping stay running
    STARTUPINFO si;
    memset(&si, 0, sizeof(STARTUPINFO));
    si.cb = sizeof(STARTUPINFO);
    PROCESS_INFORMATION pi;
    memset(&pi, 0, sizeof(PROCESS_INFORMATION));
    
    // BEGIN BLOCK A
    ::CreateProcess(NULL, "cmd /c ping 127.0.0.1 -n 10 > nul",
        NULL, NULL, TRUE, CREATE_SUSPENDED, NULL, ".", &si, &pi);
    HANDLE job = ::CeateJobObject(NULL, "myjob");
    ::AssignProcessToJobObject(job, pi.hProcess);
    // END BLOCK A
    
    ::ResumeThread(pi.hThread);
    ::CloseHandle(pi.hProcess);
    ::CloseHandle(pi.hThread);
    ::CloseHandle(job);
    HANDLE reopenJob = ::OpenJobObject(JOB_OBJECT_TERMINATE, FALSE, "myjob");
    if(reopenJob != NULL)
        ::TerminateJobObject(reopenJob, 1);
    

    The reopened job in this case is NULL, and the error code is ERROR_FILE_NOT_FOUND.

    The job must be created before the process, and be inherited, for the job to be reopenable.

    // NEW BLOCK A
    HANDLE job = ::CreateJobObject(NULL, "myjob");
    ::SetHandleInformation(job, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
    ::CreateProcess(NULL, "cmd /c ping 127.0.0.1 -n 10 > nul",
        NULL, NULL, TRUE, CREATE_SUSPENDED, NULL, ".", &si, &pi);
    ::AssignProcessToJobObject(job, pi.hProcess);
    

    If your goal is to name the job using the PID, note that this creation order prevents such a convention. This still means that some piece of information must be tracked in addition to the PID in order to reopen the job.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone help me with creating functions for the following processes? I want to
Can someone tell me why this processes all the files and then does it
I get the following error from the program below: CreateProcess failed(3) int __cdecl main(int
The following is 2 different definitions of the problem: How can I process 2
This is basic stuff but I can't get this following form to process reliably.
Our mysql processes can sometimes get backlogged and processes begin queuing up. I'd like
I have setup BPS and have created a few BPEL processes which i can
You can get underground processes by ps ux I am searching a way to
Question: How can I determine all processes in the child's Process Tree to kill
Can I initialize an IOLoop.instance and than fork new processes, which uses IOLoop.instance()? Something

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.