[Xfce4-commits] <xfce4-taskmanager:master> Implement pid_is_sleeping() and fix send_signal_to_pid()

Landry Breuil noreply at xfce.org
Sun May 16 12:58:01 CEST 2010


Updating branch refs/heads/master
         to 00d61079725fad2440e8418b67c6fb370fa02d3b (commit)
       from a721cda4bef3a7c23d897f2e3c87a6ccc8343afc (commit)

commit 00d61079725fad2440e8418b67c6fb370fa02d3b
Author: Landry Breuil <landry at rhaalovely.net>
Date:   Sun May 16 12:53:50 2010 +0200

    Implement pid_is_sleeping() and fix send_signal_to_pid()

 src/task-manager-bsd.c |   38 +++++++++++++++++++++++++++++++++-----
 1 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/src/task-manager-bsd.c b/src/task-manager-bsd.c
index 12114a1..68c1248 100644
--- a/src/task-manager-bsd.c
+++ b/src/task-manager-bsd.c
@@ -118,7 +118,19 @@ gboolean get_task_list (GArray *task_list)
 gboolean
 pid_is_sleeping (guint pid)
 {
-	return FALSE;
+	int mib[6];
+	struct kinfo_proc2 kp;
+	size_t size = sizeof(struct kinfo_proc2);
+
+	mib[0] = CTL_KERN;
+	mib[1] = KERN_PROC2;
+	mib[2] = KERN_PROC_PID;
+	mib[3] = pid;
+	mib[4] = sizeof(struct kinfo_proc2);
+	mib[5] = 1;
+	if (sysctl(mib, 6, &kp, &size, NULL, 0) < 0)
+		errx(1, "could not read kern.proc2 for pid %d", pid);
+	return (kp.p_stat == SSLEEP ? TRUE : FALSE);
 }
 
 gboolean get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system)
@@ -195,11 +207,27 @@ gboolean get_memory_usage (guint64 *memory_total, guint64 *memory_free, guint64
 	return TRUE;
 }
 
-gboolean send_signal_to_pid (guint task_id, gint signal)
+gboolean send_signal_to_pid (guint task_id, gint sig)
 {
-	gint ret = 0;
-	if(task_id > 0 && signal != 0)
-		ret = kill(task_id, signal);
+	gint ret;
+	switch (sig)
+	{
+		case XTM_SIGNAL_TERMINATE:
+			sig = SIGTERM;
+			break;
+		case XTM_SIGNAL_STOP:
+			sig = SIGSTOP;
+			break;
+		case XTM_SIGNAL_CONTINUE:
+			sig = SIGCONT;
+			break;
+		case XTM_SIGNAL_KILL:
+			sig = SIGKILL;
+			break;
+		default:
+			return TRUE;
+	}
+	ret = kill (task_id, sig);
 	return (ret == 0) ? TRUE : FALSE;
 }
 



More information about the Xfce4-commits mailing list