Pelles C forum

Pelles C => Bug reports => Topic started by: Rainer on January 11, 2007, 10:01:45 PM

Title: Undeclared identifier 'JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE'.
Post by: Rainer on January 11, 2007, 10:01:45 PM
Hello Pelle,

in the includefile winnt.h there should be the following macro:

#define JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE 0x2000

(senseless) Example-Source:


#define _WIN32_WINNT 0x0500
#include <windows.h>

int main( void )
{
HANDLE hJob;

/* Create a temporary Jobhandle */
hJob = CreateJobObject(NULL, NULL);

JOBOBJECT_EXTENDED_LIMIT_INFORMATION jeli;

QueryInformationJobObject(hJob, JobObjectExtendedLimitInformation, &jeli, sizeof(jeli),NULL);

/* Set the limitation: End Of Job => End of life of the processes (W-XP/W2K3 ff. only) */
jeli.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
SetInformationJobObject(hJob, JobObjectExtendedLimitInformation, &jeli, sizeof(jeli));

 return 0;

}
Title: Re: Undeclared identifier 'JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOS
Post by: Pelle on January 11, 2007, 10:29:49 PM
Thank you Rainer for pointing this out. I will add the definition
#define JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE  0x00002000
in the next release.
Title: Another declaration missing => IsProcessInJob
Post by: Rainer on January 12, 2007, 09:34:16 PM
Hello Pelle

just playing around with JOB_OBJECTS.

The declaration  
BOOL WINAPI IsProcessInJob (HANDLE,HANDLE,PBOOL);
is missing in Winbase.h.
(Definition too)

senseless Examplecode


#include <stdio.h>
// For JOB-Objects ...
#define _WIN32_WINNT 0x0500
#include <windows.h>
// for Processenumeration
#include <tlhelp32.h>

#define ErrorText(e,t) printf("%d %s\n",e,t)

static int ExistsAssociatedProcs(HANDLE hJob)
{

int hasProcs = TRUE; /* This is the save assument */

HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
 if ( hSnapshot != INVALID_HANDLE_VALUE )
   {
/* We got a snapshot with the processlist */
PROCESSENTRY32 pe;
BOOL proc_found;

// fill up its size
pe.dwSize  = sizeof pe;
proc_found = Process32First(hSnapshot,&pe);
if ( proc_found )
{
hasProcs = FALSE; /* HERE we assume no processes associated to the job */
do
{
HANDLE hProcess;

printf("Process ID : %08X\n",pe.th32ProcessID);
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION,FALSE,pe.th32ProcessID);
if ( hProcess )
{
BOOL is_associated;

if ( IsProcessInJob(hProcess,hJob,&is_associated) )  // <<< NOT DECLARED
{
if ( is_associated )
{
hasProcs = TRUE; /* At least one process is associated */
  break;
 /* NOTREACHED */
}
}
else
ErrorText(GetLastError(),"IsProcessInJob");

if ( !CloseHandle(hProcess) )
ErrorText(GetLastError(),"CloseHandle Process ?");
}

pe.dwSize  = sizeof pe;
proc_found = Process32Next(hSnapshot,&pe);
}
while ( proc_found );
}
else
ErrorText(GetLastError(),"Process32First: No entries found ?");

// close snapshot handle
if ( !CloseHandle(hSnapshot) )
ErrorText(GetLastError(),"CloseHandle in Snapshothandle");
   }
else
ErrorText(GetLastError(),"CreateToolhelp32Snapshot");

return hasProcs;

}

int main( void )
{
 ExistsAssociatedProcs((HANDLE)1);
 return 0;

}


By the way,
there is another missing Declaration/Definition
BOOL WINAPI CreateJobSet (ULONG,PJOB_SET_ARRAY,ULONG);
but I didn“t use it and don't know the functionality.
Title: Re: Another declaration missing => IsProcessInJob
Post by: Pelle on January 14, 2007, 05:22:11 PM
OK. I will look at all the ...job... API definitions...