Merge branch 'master' of ssh://git.xfce.org/git/apps/xfce4-taskmanager
Conflicts: src/task-manager-bsd.c
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <err.h>
|
||||
/* for getpwuid() */
|
||||
#include <sys/types.h>
|
||||
#include <pwd.h>
|
||||
@@ -26,9 +27,6 @@
|
||||
#include <sys/sysctl.h>
|
||||
/* for swapctl() */
|
||||
#include <sys/swap.h>
|
||||
/* for kill() */
|
||||
#include <signal.h>
|
||||
#include <err.h>
|
||||
/* for strlcpy() */
|
||||
#include <string.h>
|
||||
/* for getpagesize() */
|
||||
@@ -207,55 +205,3 @@ gboolean get_memory_usage (guint64 *memory_total, guint64 *memory_free, guint64
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean send_signal_to_pid (guint task_id, gint sig)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
gboolean set_priority_to_pid (guint task_id, gint prio)
|
||||
{
|
||||
gint res;
|
||||
switch (prio)
|
||||
{
|
||||
case XTM_PRIORITY_VERY_LOW:
|
||||
prio = 15;
|
||||
break;
|
||||
case XTM_PRIORITY_LOW:
|
||||
prio = 5;
|
||||
break;
|
||||
case XTM_PRIORITY_NORMAL:
|
||||
prio = 0;
|
||||
break;
|
||||
case XTM_PRIORITY_HIGH:
|
||||
prio = -5;
|
||||
break;
|
||||
case XTM_PRIORITY_VERY_HIGH:
|
||||
prio = -15;
|
||||
break;
|
||||
default:
|
||||
return TRUE;
|
||||
}
|
||||
res = setpriority (PRIO_PROCESS, task_id, prio);
|
||||
return (res == 0) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,8 +14,6 @@
|
||||
#include <pwd.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
@@ -72,13 +70,19 @@ get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system)
|
||||
fgets (buffer, 1024, file);
|
||||
sscanf (buffer, "cpu\t%u %u %u %u", &user, &user_nice, &system, &idle);
|
||||
|
||||
_cpu_count = 0;
|
||||
while (fgets (buffer, 1024, file) != NULL)
|
||||
if (_cpu_count == 0)
|
||||
{
|
||||
if (buffer[0] != 'c' && buffer[1] != 'p' && buffer[2] != 'u')
|
||||
break;
|
||||
_cpu_count += 1;
|
||||
_cpu_count = 0;
|
||||
while (fgets (buffer, 1024, file) != NULL)
|
||||
{
|
||||
if (buffer[0] != 'c' && buffer[1] != 'p' && buffer[2] != 'u')
|
||||
break;
|
||||
_cpu_count += 1;
|
||||
}
|
||||
if (_cpu_count == 0)
|
||||
_cpu_count += 1;
|
||||
}
|
||||
|
||||
fclose (file);
|
||||
|
||||
old_jiffies_user = cur_jiffies_user;
|
||||
@@ -91,8 +95,7 @@ get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system)
|
||||
|
||||
*cpu_user = (old_jiffies > 0) ? (cur_jiffies_user - old_jiffies_user) * 100 / (gdouble)(cur_jiffies - old_jiffies) : 0;
|
||||
*cpu_system = (old_jiffies > 0) ? (cur_jiffies_system - old_jiffies_system) * 100 / (gdouble)(cur_jiffies - old_jiffies) : 0;
|
||||
*cpu_count = (_cpu_count > 0) ? _cpu_count : 1;
|
||||
_cpu_count = *cpu_count;
|
||||
*cpu_count = _cpu_count;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -160,6 +163,9 @@ get_cpu_percent (guint pid, gulong jiffies_user, gfloat *cpu_user, gulong jiffie
|
||||
g_hash_table_insert (hash_cpu_user, GUINT_TO_POINTER (pid), GUINT_TO_POINTER (jiffies_user));
|
||||
g_hash_table_insert (hash_cpu_system, GUINT_TO_POINTER (pid), GUINT_TO_POINTER (jiffies_system));
|
||||
|
||||
if (jiffies_user < jiffies_user_old || jiffies_system < jiffies_system_old)
|
||||
return;
|
||||
|
||||
if (_cpu_count > 0)
|
||||
{
|
||||
*cpu_user = (jiffies_user_old > 0) ? (jiffies_user - jiffies_user_old) / (gfloat)_cpu_count : 0;
|
||||
@@ -329,58 +335,3 @@ pid_is_sleeping (guint pid)
|
||||
return (state[0] == 'T') ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
send_signal_to_pid (guint pid, gint signal)
|
||||
{
|
||||
gint sig;
|
||||
gint res;
|
||||
switch (signal)
|
||||
{
|
||||
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;
|
||||
}
|
||||
res = kill (pid, sig);
|
||||
return (res == 0) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
set_priority_to_pid (guint pid, gint priority)
|
||||
{
|
||||
gint prio;
|
||||
gint res;
|
||||
switch (priority)
|
||||
{
|
||||
case XTM_PRIORITY_VERY_LOW:
|
||||
prio = 15;
|
||||
break;
|
||||
case XTM_PRIORITY_LOW:
|
||||
prio = 5;
|
||||
break;
|
||||
case XTM_PRIORITY_NORMAL:
|
||||
prio = 0;
|
||||
break;
|
||||
case XTM_PRIORITY_HIGH:
|
||||
prio = -5;
|
||||
break;
|
||||
case XTM_PRIORITY_VERY_HIGH:
|
||||
prio = -15;
|
||||
break;
|
||||
default:
|
||||
return TRUE;
|
||||
}
|
||||
res = setpriority (PRIO_PROCESS, pid, prio);
|
||||
return (res == 0) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <pwd.h>
|
||||
#include <signal.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <glib/gi18n.h>
|
||||
@@ -92,34 +94,6 @@ _xtm_task_manager_set_model (XtmTaskManager *manager, GtkTreeModel *model)
|
||||
manager->model = model;
|
||||
}
|
||||
|
||||
void
|
||||
get_owner_uid (guint *owner_uid, gchar **owner_uid_name)
|
||||
{
|
||||
uid_t uid;
|
||||
struct passwd *pw;
|
||||
gchar *username = NULL;
|
||||
|
||||
uid = getuid ();
|
||||
pw = getpwuid (uid);
|
||||
|
||||
username = g_strdup ((pw != NULL) ? pw->pw_name : "nobody");
|
||||
|
||||
*owner_uid = (guint) uid;
|
||||
*owner_uid_name = username;
|
||||
}
|
||||
|
||||
gchar *
|
||||
get_hostname ()
|
||||
{
|
||||
#ifndef HOST_NAME_MAX
|
||||
#define HOST_NAME_MAX 255
|
||||
#endif
|
||||
char hostname[HOST_NAME_MAX];
|
||||
if (gethostname (hostname, HOST_NAME_MAX))
|
||||
return g_strdup ("(unknown)");
|
||||
return g_strdup_printf ("%s", hostname);
|
||||
}
|
||||
|
||||
static void
|
||||
model_add_task (GtkTreeModel *model, Task *task)
|
||||
{
|
||||
@@ -372,3 +346,88 @@ xtm_task_manager_update_model (XtmTaskManager *manager)
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
get_owner_uid (guint *owner_uid, gchar **owner_uid_name)
|
||||
{
|
||||
uid_t uid;
|
||||
struct passwd *pw;
|
||||
gchar *username = NULL;
|
||||
|
||||
uid = getuid ();
|
||||
pw = getpwuid (uid);
|
||||
|
||||
username = g_strdup ((pw != NULL) ? pw->pw_name : "nobody");
|
||||
|
||||
*owner_uid = (guint) uid;
|
||||
*owner_uid_name = username;
|
||||
}
|
||||
|
||||
gchar *
|
||||
get_hostname ()
|
||||
{
|
||||
#ifndef HOST_NAME_MAX
|
||||
#define HOST_NAME_MAX 255
|
||||
#endif
|
||||
char hostname[HOST_NAME_MAX];
|
||||
if (gethostname (hostname, HOST_NAME_MAX))
|
||||
return g_strdup ("(unknown)");
|
||||
return g_strdup_printf ("%s", hostname);
|
||||
}
|
||||
|
||||
gboolean
|
||||
send_signal_to_pid (guint pid, gint signal)
|
||||
{
|
||||
gint sig;
|
||||
gint res;
|
||||
switch (signal)
|
||||
{
|
||||
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;
|
||||
}
|
||||
res = kill (pid, sig);
|
||||
return (res == 0) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
set_priority_to_pid (guint pid, gint priority)
|
||||
{
|
||||
gint prio;
|
||||
gint res;
|
||||
switch (priority)
|
||||
{
|
||||
case XTM_PRIORITY_VERY_LOW:
|
||||
prio = 15;
|
||||
break;
|
||||
case XTM_PRIORITY_LOW:
|
||||
prio = 5;
|
||||
break;
|
||||
case XTM_PRIORITY_NORMAL:
|
||||
prio = 0;
|
||||
break;
|
||||
case XTM_PRIORITY_HIGH:
|
||||
prio = -5;
|
||||
break;
|
||||
case XTM_PRIORITY_VERY_HIGH:
|
||||
prio = -15;
|
||||
break;
|
||||
default:
|
||||
return TRUE;
|
||||
}
|
||||
res = setpriority (PRIO_PROCESS, pid, prio);
|
||||
return (res == 0) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,12 +63,10 @@ enum
|
||||
* OS specific implementation.
|
||||
*/
|
||||
|
||||
gboolean get_memory_usage (guint64 *memory_total, guint64 *memory_free, guint64 *memory_cache, guint64 *memory_buffers, guint64 *swap_total, guint64 *swap_free);
|
||||
gboolean get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system);
|
||||
gboolean get_task_list (GArray *task_list);
|
||||
gboolean pid_is_sleeping (guint pid);
|
||||
gboolean send_signal_to_pid (guint pid, gint signal);
|
||||
gboolean set_priority_to_pid (guint pid, gint priority);
|
||||
gboolean get_memory_usage (guint64 *memory_total, guint64 *memory_free, guint64 *memory_cache, guint64 *memory_buffers, guint64 *swap_total, guint64 *swap_free);
|
||||
gboolean get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system);
|
||||
gboolean get_task_list (GArray *task_list);
|
||||
gboolean pid_is_sleeping (guint pid);
|
||||
|
||||
/**
|
||||
* GObject class used to update the graphical widgets.
|
||||
@@ -95,7 +93,9 @@ void xtm_task_manager_update_model (XtmTaskManager *manager);
|
||||
* Helper functions.
|
||||
*/
|
||||
|
||||
void get_owner_uid (guint *owner_uid, gchar **owner_uid_name);
|
||||
gchar * get_hostname ();
|
||||
void get_owner_uid (guint *owner_uid, gchar **owner_uid_name);
|
||||
gchar * get_hostname ();
|
||||
gboolean send_signal_to_pid (guint pid, gint signal);
|
||||
gboolean set_priority_to_pid (guint pid, gint priority);
|
||||
|
||||
#endif /* !TASK_MANAGER_H */
|
||||
|
||||
Reference in New Issue
Block a user