1
/* Procman process actions
2
* Copyright (C) 2001 Kevin Vandersloot
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU Library General Public
15
* License along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
26
#include <sys/resource.h>
27
#include "procactions.h"
29
#include "proctable.h"
30
#include "procdialogs.h"
31
#include "callbacks.h"
33
static int nice_value = 0;
36
renice_single_process (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
38
ProcData *procdata = data;
39
ProcInfo *info = NULL;
44
gtk_tree_model_get (model, iter, COL_POINTER, &info, -1);
45
g_return_if_fail (info);
48
error = setpriority (PRIO_PROCESS, info->pid, nice_value);
53
error_msg = g_strdup_printf (_("No such process."));
54
dialog = gtk_message_dialog_new (NULL,
55
GTK_DIALOG_DESTROY_WITH_PARENT,
61
gtk_dialog_run (GTK_DIALOG (dialog));
62
gtk_widget_destroy (dialog);
66
error_msg = g_strdup_printf (_("Process Name: %s \n\nYou do not have permission to change the priority of this process. You can enter the root password to gain the necessary permission."), info->name);
67
procdialog_create_root_password_dialog (1, procdata,
68
info->pid, nice_value,
73
error_msg = g_strdup_printf (_("Process Name: %s \n\nYou must be root to renice a process lower than 0. You can enter the root password to gain the necessary permission."), info->name);
74
procdialog_create_root_password_dialog (1, procdata,
75
info->pid, nice_value,
87
renice (ProcData *procdata, int pid, int nice)
91
/*if (!procdata->selection)
94
gtk_tree_selection_selected_foreach (procdata->selection, renice_single_process,
96
proctable_update_all (procdata);
101
kill_single_process (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
103
ProcData *procdata = data;
109
gtk_tree_model_get (model, iter, COL_POINTER, &info, -1);
110
g_return_if_fail (info);
112
/* Author: Tige Chastian
114
Added dialogs for errors on kill.
115
Added sigterm fail over to sigkill
117
error = kill (info->pid, kill_signal);
124
error_msg = g_strdup_printf (_("Process Name: %s \n\nYou do not have permission to end this process. You can enter the root password to gain the necessary permission."), info->name);
125
procdialog_create_root_password_dialog (0, procdata,
126
info->pid, kill_signal,
131
error = kill (info->pid, SIGKILL);
138
dialog = gtk_message_dialog_new (NULL,
139
GTK_DIALOG_DESTROY_WITH_PARENT,
143
_("An error occured while killing the process."),
145
gtk_dialog_run (GTK_DIALOG (dialog));
146
gtk_widget_destroy (dialog);
157
kill_process (ProcData *procdata, int sig)
159
/* EEEK - ugly hack - make sure the table is not updated as a crash
160
** occurs if you first kill a process and the tree node is removed while
161
** still in the foreach function
163
gtk_timeout_remove (procdata->timeout);
167
gtk_tree_selection_selected_foreach (procdata->selection, kill_single_process,
170
procdata->timeout = gtk_timeout_add (procdata->config.update_interval,
171
cb_timeout, procdata);
172
proctable_update_all (procdata);