29 # include <tlhelp32.h> 32 # include "sys/resource.h" 43 float priority =
mUdf(
float);
44 clp.
getVal(
"priority", priority );
48 int nicelvl =
mUdf(
int);
49 if ( !clp.
getVal(
"nice",nicelvl) )
52 setpriority( PRIO_PROCESS, pid, nicelvl );
58 setpriority( PRIO_PROCESS, pid, machprio );
66 const DWORD threadpriority =
67 machprio == 8 ? THREAD_PRIORITY_NORMAL
68 : ( machprio == 7 ? THREAD_PRIORITY_BELOW_NORMAL
69 : THREAD_PRIORITY_LOWEST );
70 if ( threadpriority != THREAD_PRIORITY_NORMAL )
71 SetPriorityClass( GetCurrentProcess(), BELOW_NORMAL_PRIORITY_CLASS );
73 HANDLE curthread = INVALID_HANDLE_VALUE;
74 THREADENTRY32 threadlist;
76 const DWORD dwOwnerPID( GetCurrentProcessId() );
77 curthread = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, dwOwnerPID );
78 if ( curthread == INVALID_HANDLE_VALUE )
81 threadlist.dwSize =
sizeof(THREADENTRY32);
82 if ( !Thread32First(curthread,&threadlist) )
83 { CloseHandle(curthread);
return; }
87 if ( threadlist.th32OwnerProcessID != dwOwnerPID )
90 SetThreadPriority(curthread,threadpriority );
91 }
while ( Thread32Next(curthread,&threadlist) );
93 CloseHandle( curthread );
102 if ( !
BP().stillok_ )
108 bool allok = bp.initOutput();
118 logstrm <<
"Starting program: " << argv[0] <<
" " << bp.
name() <<
"\n";
120 logstrm <<
"Process ID: " << pid <<
"\n";
121 allok = bp.
go( logstrm );
125 BatchProgram::deleteInstance();
127 return allok ? 0 : 1;
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:285
OD class for stream write common access to the user log file, or std::cout in batch progs...
Definition: od_ostream.h:25
bool go(od_ostream &log_stream)
This method must be defined by user.
StreamData & sdout_
Definition: batchprog.h:95
static int getMachinePriority(float priolevel, bool iswin)
void loadAuto(bool late)
see class comments
Definition: commandlineparser.h:49
static void setBatchPriority(int argc, char **argv, int pid)
Definition: _execbatch.h:39
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:270
std::ostream * oStrm() const
Definition: strmdata.h:51
Main object for 'standard' batch programs.
Definition: batchprog.h:48
int Execute_batch(int *pargc, char **argv)
Definition: _execbatch.h:97
bool getVal(const char *key, BufferString &, bool acceptnone=false, int valnr=1) const
bool stillok_
Definition: batchprog.h:93
virtual const OD::String & name() const
Definition: namedobj.h:33
static const char * localHostName()