[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: KProcess Nice level
From:       Oswald Buddenhagen <ossi () kde ! org>
Date:       2003-05-26 10:57:40
[Download RAW message or body]

On Fri, May 23, 2003 at 08:41:14PM +0200, Luis Pedro Coelho wrote:
> > > but i could add a setNice() function, too.
> >
> > If you do that, please rename it to setPriority() afterwards :]
> 
> Good idea.
>
here is a patch.

> Add a couple of priority constants as well (Priority::High,
> Priority::Normal, Priority::Low, Priority::VeryLow) since the standard
> 19 to -19 (or is it 20 to -19, or whatever) is not really friendly -
>
i'm not sure this is a good idea. the programmer using the call should
be familiar with the "nice scale".

> there should be a way to specify the exact posix style value, of course.
> 
the linux man page does not mention posix ...
in fact, it seems like a possible todo to add some math for systems that
use priorities outside the range -20 ... 19 (dunno if we support any of
these systems, though).

greetings

-- 
Hi! I'm a .signature virus! Copy me into your ~/.signature, please!
--
Chaos, panic, and disorder - my work here is done.

["kprocess.diff" (text/plain)]

Index: kprocess.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kprocess.cpp,v
retrieving revision 1.123
diff -u -r1.123 kprocess.cpp
--- kprocess.cpp	6 May 2003 16:57:52 -0000	1.123
+++ kprocess.cpp	26 May 2003 10:50:28 -0000
@@ -86,7 +86,7 @@
    KProcessPrivate() : 
      usePty(KProcess::NoCommunication),
      addUtmp(false), useShell(false),
-     pty(0)
+     pty(0), prio(0)
    {
    }
 
@@ -97,6 +97,8 @@
    KPty *pty;
    const char *user;
 
+   int prio;
+
    QMap<QString,QString> env;
    QString wd;
    QCString shell;
@@ -196,6 +198,14 @@
    return keepPrivs;
 }
 
+bool
+KProcess::setPriority(int prio)
+{
+    d->prio = prio;
+    if (runs)
+	return !setpriority(PRIO_PROCESS, pid_, prio);
+    return true;
+}
 
 KProcess::~KProcess()
 {
@@ -360,6 +370,9 @@
 #endif
            setuid(getuid());
         }
+
+        if (d->prio)
+            setpriority(PRIO_PROCESS, 0, d->prio);
 
         setupEnvironment();
 
Index: kprocess.h
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kprocess.h,v
retrieving revision 1.77
diff -u -r1.77 kprocess.h
--- kprocess.h	6 May 2003 17:00:25 -0000	1.77
+++ kprocess.h	26 May 2003 10:50:28 -0000
@@ -499,6 +499,14 @@
    */
   KPty *pty() const;
 
+  /**
+   * Sets the scheduling priority of the process.
+   * @param prio the new priority in the range -20 (high) to 19 (low).
+   * @return false on error; see setpriority(2) for possible reasons.
+   * @since 3.2
+   */
+  bool setPriority(int prio);
+
 signals:
   /**
    * Emitted after the process has terminated when


>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic