Experimental feature: beep on permission failures.

Update dates.
This commit is contained in:
Hisham Muhammad 2007-12-17 05:57:28 +00:00
parent a839c3f2ca
commit cf7fdcd1d6
3 changed files with 34 additions and 25 deletions

View File

@ -42,7 +42,7 @@ typedef enum ProcessField_ {
STIME, CUTIME, CSTIME, PRIORITY, NICE, ITREALVALUE, STARTTIME, VSIZE, RSS, RLIM, STARTCODE, ENDCODE,
STARTSTACK, KSTKESP, KSTKEIP, SIGNAL, BLOCKED, SSIGIGNORE, SIGCATCH, WCHAN, NSWAP, CNSWAP, EXIT_SIGNAL,
PROCESSOR, M_SIZE, M_RESIDENT, M_SHARE, M_TRS, M_DRS, M_LRS, M_DT, ST_UID, PERCENT_CPU, PERCENT_MEM,
USER, TIME, NLWP, TGID
USER, TIME, NLWP, TGID,
#ifdef HAVE_OPENVZ
VEID, VPID,
#endif
@ -187,12 +187,13 @@ void Process_toggleTag(Process* this) {
this->tag = this->tag == true ? false : true;
}
void Process_setPriority(Process* this, int priority) {
bool Process_setPriority(Process* this, int priority) {
int old_prio = getpriority(PRIO_PROCESS, this->pid);
int err = setpriority(PRIO_PROCESS, this->pid, priority);
if (err == 0 && old_prio != getpriority(PRIO_PROCESS, this->pid)) {
this->nice = priority;
}
return (err == 0);
}
unsigned long Process_getAffinity(Process* this) {
@ -201,8 +202,8 @@ unsigned long Process_getAffinity(Process* this) {
return mask;
}
void Process_setAffinity(Process* this, unsigned long mask) {
sched_setaffinity(this->pid, sizeof(unsigned long), (cpu_set_t*) &mask);
bool Process_setAffinity(Process* this, unsigned long mask) {
return (sched_setaffinity(this->pid, sizeof(unsigned long), (cpu_set_t*) &mask) == 0);
}
void Process_sendSignal(Process* this, int signal) {

View File

@ -141,11 +141,11 @@ void Process_display(Object* cast, RichString* out);
void Process_toggleTag(Process* this);
void Process_setPriority(Process* this, int priority);
bool Process_setPriority(Process* this, int priority);
unsigned long Process_getAffinity(Process* this);
void Process_setAffinity(Process* this, unsigned long mask);
bool Process_setAffinity(Process* this, unsigned long mask);
void Process_sendSignal(Process* this, int signal);

28
htop.c
View File

@ -1,6 +1,6 @@
/*
htop - htop.c
(C) 2004-2006 Hisham H. Muhammad
(C) 2004-2007 Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
@ -36,14 +36,14 @@ in the source distribution for its full text.
void printVersionFlag() {
clear();
printf("htop " VERSION " - (C) 2004-2006 Hisham Muhammad.\n");
printf("htop " VERSION " - (C) 2004-2007 Hisham Muhammad.\n");
printf("Released under the GNU GPL.\n\n");
exit(0);
}
void printHelpFlag() {
clear();
printf("htop " VERSION " - (C) 2004-2006 Hisham Muhammad.\n");
printf("htop " VERSION " - (C) 2004-2007 Hisham Muhammad.\n");
printf("Released under the GNU GPL.\n\n");
printf("-d DELAY Delay between updates, in tenths of seconds\n\n");
printf("-u USERNAME Show only processes of a given user\n\n");
@ -56,7 +56,7 @@ void printHelpFlag() {
void showHelp(ProcessList* pl) {
clear();
attrset(CRT_colors[HELP_BOLD]);
mvaddstr(0, 0, "htop " VERSION " - (C) 2004-2006 Hisham Muhammad.");
mvaddstr(0, 0, "htop " VERSION " - (C) 2004-2007 Hisham Muhammad.");
mvaddstr(1, 0, "Released under the GNU GPL. See 'man' page for more info.");
attrset(CRT_colors[DEFAULT_COLOR]);
@ -151,18 +151,21 @@ static void Setup_run(Settings* settings, int headerHeight) {
}
static bool changePriority(Panel* panel, int delta) {
bool ok = true;
bool anyTagged = false;
for (int i = 0; i < Panel_getSize(panel); i++) {
Process* p = (Process*) Panel_get(panel, i);
if (p->tag) {
Process_setPriority(p, p->nice + delta);
ok = Process_setPriority(p, p->nice + delta) && ok;
anyTagged = true;
}
}
if (!anyTagged) {
Process* p = (Process*) Panel_getSelected(panel);
Process_setPriority(p, p->nice + delta);
ok = Process_setPriority(p, p->nice + delta) && ok;
}
if (!ok)
beep();
return anyTagged;
}
@ -608,20 +611,25 @@ int main(int argc, char** argv) {
Panel* affinityPanel = AffinityPanel_new(pl->processorCount, curr);
char* fuFunctions[2] = {"Toggle ", "Done "};
pickFromList(panel, affinityPanel, 15, headerHeight, fuFunctions, defaultBar);
char* fuFunctions[2] = {"Set ", "Cancel "};
void* set = pickFromList(panel, affinityPanel, 15, headerHeight, fuFunctions, defaultBar);
if (set) {
unsigned long new = AffinityPanel_getAffinity(affinityPanel);
bool anyTagged = false;
bool ok = true;
for (int i = 0; i < Panel_getSize(panel); i++) {
Process* p = (Process*) Panel_get(panel, i);
if (p->tag) {
Process_setAffinity(p, new);
ok = Process_setAffinity(p, new) && ok;
anyTagged = true;
}
}
if (!anyTagged) {
Process* p = (Process*) Panel_getSelected(panel);
Process_setAffinity(p, new);
ok = Process_setAffinity(p, new) && ok;
}
if (!ok)
beep();
}
((Object*)affinityPanel)->delete((Object*)affinityPanel);
Panel_setRichHeader(panel, ProcessList_printHeader(pl));