31 # include <tlhelp32.h> 34 # include "sys/resource.h" 45 float priority =
mUdf(
float);
46 clp.
getVal(
"priority", priority );
50 int nicelvl =
mUdf(
int);
51 if ( !clp.
getVal(
"nice",nicelvl) )
54 setpriority( PRIO_PROCESS, pid, nicelvl );
60 setpriority( PRIO_PROCESS, pid, machprio );
68 const DWORD threadpriority =
69 machprio == 8 ? THREAD_PRIORITY_NORMAL
70 : ( machprio == 7 ? THREAD_PRIORITY_BELOW_NORMAL
71 : THREAD_PRIORITY_LOWEST );
72 if ( threadpriority != THREAD_PRIORITY_NORMAL )
73 SetPriorityClass( GetCurrentProcess(), BELOW_NORMAL_PRIORITY_CLASS );
75 HANDLE curthread = INVALID_HANDLE_VALUE;
76 THREADENTRY32 threadlist;
78 const DWORD dwOwnerPID( GetCurrentProcessId() );
79 curthread = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, dwOwnerPID );
80 if ( curthread == INVALID_HANDLE_VALUE )
83 threadlist.dwSize =
sizeof(THREADENTRY32);
84 if ( !Thread32First(curthread,&threadlist) )
85 { CloseHandle(curthread);
return; }
89 if ( threadlist.th32OwnerProcessID != dwOwnerPID )
92 SetThreadPriority(curthread,threadpriority );
93 }
while ( Thread32Next(curthread,&threadlist) );
95 CloseHandle( curthread );
104 if ( !
BP().stillok_ )
110 bool allok = bp.initOutput();
120 logstrm <<
"Starting program: " << argv[0] <<
" " << bp.
name()
123 logstrm <<
"Process ID: " << pid <<
od_endl;
124 allok = bp.
go( logstrm );
128 BatchProgram::deleteInstance();
130 return allok ? 0 : 1;
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:287
OD class for stream write common access to the user log file, or std::cout in batch progs...
Definition: od_ostream.h:26
bool go(od_ostream &log_stream)
This method must be defined by user.
StreamData & sdout_
Definition: batchprog.h:98
static int getMachinePriority(float priolevel, bool iswin)
void loadAuto(bool late)
see class comments
od_ostream & od_endl(od_ostream &strm)
Definition: od_ostream.h:111
Definition: commandlineparser.h:51
static void setBatchPriority(int argc, char **argv, int pid)
Definition: _execbatch.h:41
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:272
Main object for 'standard' batch programs.
Definition: batchprog.h:49
int Execute_batch(int *pargc, char **argv)
Definition: _execbatch.h:99
bool getVal(const char *key, BufferString &, bool acceptnone=false, int valnr=1) const
std::ostream * ostrm
Definition: strmdata.h:44
bool stillok_
Definition: batchprog.h:96
virtual const OD::String & name() const
Definition: namedobj.h:47
static const char * localHostName()
shortcut to GetLocalHostName()