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

List:       kde-commits
Subject:    branches/work/kdehw/solidstats
From:       John Tapsell <john.tapsell () kdemail ! net>
Date:       2007-03-02 20:59:37
Message-ID: 1172869177.140758.27196.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 638672 by johnflux:

Add kill and set priority functions


 M  +22 -0     processes.cpp  
 M  +37 -0     processes.h  
 M  +22 -0     processes_linux.cpp  
 M  +21 -0     processes_local.h  


--- branches/work/kdehw/solidstats/processes.cpp #638671:638672
@@ -33,7 +33,10 @@
 //for sysconf
 #include <unistd.h>  
 
+/* if porting to an OS without signal.h  please #define SIGTERM to something */
+#include <signal.h>
 
+
 namespace Solid
 {
 
@@ -170,6 +173,25 @@
     delete process;
 }
 
+
+bool Processes::killProcess(long pid) {
+  return sendSignal(pid, SIGTERM);
+}
+
+bool Processes::sendSignal(long pid, int sig) {
+    if(!d) {
+        d = new Private();
+    }
+    return d->processesLocal.sendSignal(pid, sig);
+}
+
+bool Processes::setNiceness(long pid, int priority) {
+    if(!d) {
+        d = new Private();
+    }
+    return d->processesLocal.setNiceness(pid, priority);
+}
+
 Processes::~Processes()
 {
   
--- branches/work/kdehw/solidstats/processes.h #638671:638672
@@ -50,6 +50,43 @@
 	 *  The key to the hash is the pid of the process.
 	 */
 	static QHash<long, Process *> getProcesses();
+
+	/**
+	 *  Get information for one specific process
+	 */
+	static Process *getProcess(long pid);
+
+	/**
+	 *  Kill the specified process.  You may not have the privillage to kill the process.
+	 *  The process may also chose to ignore the command.  Send the SIGKILL signal to kill
+	 *  the process immediately.  You may lose any unsaved data.
+	 *
+	 *  @returns Successful or not in killing the process
+	 */
+	static bool killProcess(long pid);
+
+        /**
+	 *  Send the specified named POSIX signal to the process given.
+	 *
+	 *  For example, to indicate for process 324 to STOP do:
+	 *  \code
+	 *    #include <signals.h>
+	 *     ...
+	 *
+	 *    Solid::Processes::sendSignal(23, SIGSTOP);
+	 *  \endcode
+	 *
+	 */
+	static bool sendSignal(long pid, int sig);
+
+	/**
+	 *  Set the priority for a process.  This is from 19 (very nice, lowest priority) to 
+	 *    -20 (highest priority).  The default value for a process is 0.
+	 *  
+	 *  @return false if you do not have permission to set the priority
+	 */
+	static bool setNiceness(long pid, int priority);
+
     protected:
 
 	Processes();
--- branches/work/kdehw/solidstats/processes_linux.cpp #638671:638672
@@ -31,8 +31,14 @@
 
 //for sysconf
 #include <unistd.h>  
+//for kill and setNice
+#include <sys/types.h>
+#include <signal.h>
+#include <sys/resource.h>
 
 
+
+
 namespace Solid
 {
 
@@ -213,6 +219,22 @@
     return pids;
 }
 
+bool ProcessesLocal::sendSignal(long pid, int sig) {
+    if ( kill( (pid_t)pid, sig ) ) {
+	//Kill failed
+        return false;
+    }
+    return true;
+}
+bool ProcessesLocal::setNiceness(long pid, int priority) {
+    if ( setpriority( PRIO_PROCESS, pid, priority ) ) {
+	    //set niceness failed
+	    return false;
+    }
+    return true;
+}
+
+
 ProcessesLocal::~ProcessesLocal()
 {
   
--- branches/work/kdehw/solidstats/processes_local.h #638671:638672
@@ -58,7 +58,28 @@
 	 *  will be non null.  
 	 */ 
         bool updateProcessInfo(long pid, Process *process);
+        /**
+	 *  Send the specified named POSIX signal to the process given.
+	 *
+	 *  For example, to indicate for process 324 to STOP do:
+	 *  \code
+	 *    #include <signals.h>
+	 *     ...
+	 *
+	 *    Solid::Processes::sendSignal(23, SIGSTOP);
+	 *  \endcode
+	 *
+	 */
+	bool sendSignal(long pid, int sig);
 
+	/**
+	 *  Set the priority for a process.  This is from 19 (very nice, lowest priority) to 
+	 *    -20 (highest priority).  The default value for a process is 0.
+	 *  
+	 *  @return false if you do not have permission to set the priority
+	 */
+	bool setNiceness(long pid, int priority);
+
 	ProcessesLocal();
 	~ProcessesLocal();
       private:
[prev in list] [next in list] [prev in thread] [next in thread] 

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