1 /* This file is part of the KDE Project
2 Copyright (c) 2008 Sebastian Trueg <trueg@kde.org>
4 Parts of this file are based on code from Strigi
5 Copyright (C) 2006-2007 Jos van den Oever <jos@vandenoever.info>
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License version 2 as published by the Free Software Foundation.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
28 #include <QtCore/QDebug>
31 #include <sys/resource.h>
34 #include <sys/syscall.h>
42 #ifndef IOPRIO_CLASS_IDLE
51 #ifndef IOPRIO_WHO_PROCESS
53 IOPRIO_WHO_PROCESS
= 1,
59 #ifndef IOPRIO_CLASS_SHIFT
60 const int IOPRIO_CLASS_SHIFT
= 13;
66 bool lowerIOPriority()
69 if ( syscall( SYS_ioprio_set
, IOPRIO_WHO_PROCESS
, 0, IOPRIO_CLASS_IDLE
<<IOPRIO_CLASS_SHIFT
) < 0 ) {
70 qDebug( "cannot set io scheduling to idle (%s). Trying best effort.\n", strerror( errno
));
71 if ( syscall( SYS_ioprio_set
, IOPRIO_WHO_PROCESS
, 0, 7|IOPRIO_CLASS_BE
<<IOPRIO_CLASS_SHIFT
) < 0 ) {
72 qDebug( "cannot set io scheduling to best effort.\n");
85 return !setpriority( PRIO_PROCESS
, 0, 19 );
89 // FIXME: is this really useful? Should we better use SCHED_IDLE?
90 bool lowerSchedulingPriority()
93 struct sched_param param
;
94 memset( ¶m
, 0, sizeof(param
) );
95 param
.sched_priority
= 0;
96 return !sched_setscheduler( 0, SCHED_BATCH
, ¶m
);