Add wxProcess::SetPriority() to allow setting the priority of child processes.
This uses the same conventions as wxThread::SetPriority() but works on the entire process. Closes #14931. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73406 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -132,6 +132,10 @@
|
||||
#include <sys/sysinfo.h> // for SAGET and MINFO structures
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SETPRIORITY
|
||||
#include <sys/resource.h> // for setpriority()
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// conditional compilation
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -545,6 +549,21 @@ long wxExecute(char **argv, int flags, wxProcess *process,
|
||||
}
|
||||
}
|
||||
|
||||
// priority: we need to map wxWidgets priority which is in the range 0..100
|
||||
// to Unix nice value which is in the range -20..19. As there is an odd
|
||||
// number of elements in our range and an even number in the Unix one, we
|
||||
// have to do it in this rather ugly way to guarantee that:
|
||||
// 1. wxPRIORITY_{MIN,DEFAULT,MAX} map to -20, 0 and 19 respectively.
|
||||
// 2. The mapping is monotonously increasing.
|
||||
// 3. The mapping is onto the target range.
|
||||
int prio = process->GetPriority();
|
||||
if ( prio <= 50 )
|
||||
prio = (2*prio)/5 - 20;
|
||||
else if ( prio < 55 )
|
||||
prio = 1;
|
||||
else
|
||||
prio = (2*prio)/5 - 21;
|
||||
|
||||
// fork the process
|
||||
//
|
||||
// NB: do *not* use vfork() here, it completely breaks this code for some
|
||||
@@ -578,6 +597,13 @@ long wxExecute(char **argv, int flags, wxProcess *process,
|
||||
}
|
||||
#endif // !__VMS
|
||||
|
||||
#if defined(HAVE_SETPRIORITY)
|
||||
if ( setpriority(PRIO_PROCESS, 0, prio) != 0 )
|
||||
{
|
||||
wxLogSysError(_("Failed to set process priority"));
|
||||
}
|
||||
#endif // HAVE_SETPRIORITY
|
||||
|
||||
// redirect stdin, stdout and stderr
|
||||
if ( pipeIn.IsOk() )
|
||||
{
|
||||
|
Reference in New Issue
Block a user