c++ - AssignProcessToJobObject Failing The Handle is Invalid -
im creating job createjobobjecta(), creating new process createprocessa(), , when try assign new process job have created assignprocesstojobobject() returns 0. getlasterror() , im getting value of 6. according windows systems error code means handle invalid. heres code.
handle job = createjobobjecta( null, "jobname" ); if( job == null ) { printf( "job null" ); } else { jobject_extended_limit_information jeli = { 0 }; jeli.basiclimitinformation.limitflags = job_object_limit_kill_on_job_close; if( 0 == setinformationjobobject( job, jobobjectextendedlimitinformation, &jeli, sizeof(jeli))) { printf("could not setinformationjobobject\n"); } } if( createprocessa( "c:\\windows\\syswow64\\cmd.exe", "/c server.bat", null, null, true, 0, null, null, &info, &processinfo)) { printf("createprocess succeeded.\n"); if( job != null ) { handle derp = processinfo.hprocess; if( derp != null ) { if( 0 == assignprocesstojobobject( job, derp )) { printf("could not assignprocesstoobject\n"); dword err = getlasterror(); printf("derp"); } } } //can free handles now? not sure this. closehandle(processinfo.hprocess); closehandle(processinfo.hthread); }
the bat file doing supposed doing , launching jar runs server. dont how handle invalid. amazing. or possibly different way this?
i want launch new process , have child process when main process crashes server closes also.
thank you.
you've got race condition. if cmd.exe
exits before call assignprocesstojobobject
won't work (i'm not sure error code in scenario).
start process suspended using create_suspended
flag , don't resume until you've assigned job.
Comments
Post a Comment