[Xfce4-commits] <xfce4-taskmanager:master> Implement new function pid_is_sleeping()
Mike Massonnet
noreply at xfce.org
Sun May 9 01:44:03 CEST 2010
Updating branch refs/heads/master
to 1788e3c2201d05c5cef5026756c7e96edb075b74 (commit)
from 07131a81b3b52a5b856c81e2bc353a6b2d22f8fe (commit)
commit 1788e3c2201d05c5cef5026756c7e96edb075b74
Author: Mike Massonnet <mmassonnet at xfce.org>
Date: Sun May 9 01:34:56 2010 +0200
Implement new function pid_is_sleeping()
The function pid_is_sleeping() is implement by the different OS
implementations and returns TRUE or FALSE. It is used in the tree view
context menu to show either the signal Stop or Continue.
src/process-tree-view.c | 25 ++++++++++++++-----------
src/task-manager-linux.c | 18 +++++++++++++++++-
2 files changed, 31 insertions(+), 12 deletions(-)
diff --git a/src/process-tree-view.c b/src/process-tree-view.c
index 5b0bdcc..7fb7374 100644
--- a/src/process-tree-view.c
+++ b/src/process-tree-view.c
@@ -185,17 +185,20 @@ build_context_menu (guint pid)
gtk_container_add (GTK_CONTAINER (menu), mi);
g_signal_connect (mi, "activate", G_CALLBACK (cb_send_signal), GINT_TO_POINTER (XTM_SIGNAL_TERMINATE));
- // TODO look up task for building menu with either Stop or Continue and in an OS-independent way
- // if (pid_is_sleeping (pid))
- mi = gtk_menu_item_new_with_label (_("Stop"));
- g_object_set_data (G_OBJECT (mi), "pid", GUINT_TO_POINTER (pid));
- gtk_container_add (GTK_CONTAINER (menu), mi);
- g_signal_connect (mi, "activate", G_CALLBACK (cb_send_signal), GINT_TO_POINTER (XTM_SIGNAL_STOP));
-
- mi = gtk_menu_item_new_with_label (_("Continue"));
- g_object_set_data (G_OBJECT (mi), "pid", GUINT_TO_POINTER (pid));
- gtk_container_add (GTK_CONTAINER (menu), mi);
- g_signal_connect (mi, "activate", G_CALLBACK (cb_send_signal), GINT_TO_POINTER (XTM_SIGNAL_CONTINUE));
+ if (!pid_is_sleeping (pid))
+ {
+ mi = gtk_menu_item_new_with_label (_("Stop"));
+ g_object_set_data (G_OBJECT (mi), "pid", GUINT_TO_POINTER (pid));
+ gtk_container_add (GTK_CONTAINER (menu), mi);
+ g_signal_connect (mi, "activate", G_CALLBACK (cb_send_signal), GINT_TO_POINTER (XTM_SIGNAL_STOP));
+ }
+ else
+ {
+ mi = gtk_menu_item_new_with_label (_("Continue"));
+ g_object_set_data (G_OBJECT (mi), "pid", GUINT_TO_POINTER (pid));
+ gtk_container_add (GTK_CONTAINER (menu), mi);
+ g_signal_connect (mi, "activate", G_CALLBACK (cb_send_signal), GINT_TO_POINTER (XTM_SIGNAL_CONTINUE));
+ }
mi = gtk_menu_item_new_with_label (_("Kill"));
g_object_set_data (G_OBJECT (mi), "pid", GUINT_TO_POINTER (pid));
diff --git a/src/task-manager-linux.c b/src/task-manager-linux.c
index 3d61ab7..ece59d5 100644
--- a/src/task-manager-linux.c
+++ b/src/task-manager-linux.c
@@ -310,7 +310,23 @@ get_task_list (GArray *task_list)
gboolean
pid_is_sleeping (guint pid)
{
- return TRUE;
+ FILE *file;
+ gchar filename[96];
+ gchar buffer[1024];
+ gchar state[2];
+
+ snprintf (filename, 96, "/proc/%i/status", pid);
+ if ((file = fopen (filename, "r")) == NULL)
+ return FALSE;
+
+ while (fgets (buffer, 1024, file) != NULL)
+ {
+ if (sscanf (buffer, "State:\t%1s", state) > 0)
+ break;
+ }
+ fclose (file);
+
+ return (state[0] == 'T') ? TRUE : FALSE;
}
gboolean
More information about the Xfce4-commits
mailing list