Go Back   Science Forums
View Single Post
Old 05-15-2008   #18 (permalink)
alexander's Avatar
alexander
Dedicated Smart-ass




Location:
Just before 0xAA55
 
alexander has a reputation beyond reputealexander has a reputation beyond reputealexander has a reputation beyond reputealexander has a reputation beyond reputealexander has a reputation beyond reputealexander has a reputation beyond reputealexander has a reputation beyond reputealexander has a reputation beyond reputealexander has a reputation beyond reputealexander has a reputation beyond repute
Send a message via AIM to alexander
 



Not Ranked  0 score     
Re: Hypography Distributed Computing Team

just put up my third system on this

this one is nix, and its supposed to run transparently (shhh)

my biggest problem is that on nix, boinc has not provided a way to limit cpu usage, and for me, it's a big deal, when i am installing it on a future router....

i think i may have found a solution though
Code:
//cpulimit.c
/**
* Simple program to limit the cpu usage of a process
*
* Author: Angelo Marletta (marlonx80@hotmail.com)
*/

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <unistd.h>
#include <sys/types.h>
#include <signal.h>
#include <sys/resource.h>

//pid of the controlled process
int pid;

//SIGINT signal handler
void quit(int sig) {
//let the process continue if it's stopped
kill(pid,SIGCONT);
exit(0);
}

int main(int argc, char **argv) {

if (argc!=3) {
fprintf(stderr,"Usage: %s {pid} {max cpu percentage}n",argv[0]);
exit(1);
}
pid=atoi(argv[1]);
int limit=atoi(argv[2]);
if (limit>100 || limit<0) {
fprintf(stderr,"limit must be in the range 0-100n");
exit(1);
}
//if possible renice this process, so it has more responsiveness
if (setpriority(PRIO_PROCESS,getpid(),-20)!=0) {
printf("Warning: cannot renice.nTo work better you should run this program as root.n");
}
signal(SIGINT,quit);

//time quantum in microseconds
int period=100000;
struct timespec twork,tsleep; //time to work, and time to sleep
twork.tv_sec=0;
twork.tv_nsec=period*limit*10;
tsleep.tv_sec=0;
tsleep.tv_nsec=period*(100-limit)*10;

while(1) {
if (kill(pid,SIGSTOP)!=0) break;
nanosleep(&tsleep,NULL);
if (kill(pid,SIGCONT)!=0) break;
nanosleep(&twork,NULL);
}

perror("kill()");
exit(1);
}


----------------
Microsoft, the leader in using innovative tactics to promote irksome experience, coupled with antiquated technology that's held together by a pyramid of makeshift afterthoughts.

Apple, the leader in using irksome tactics to promote innovative experience, coupled with an antiquated core that's enhanced by state-of-the-art afterthoughts.

Linux, the leader in not using any tactics to promote user-defined experience, coupled with state-of-the-art core enhanced by innovative afterthoughts.


Last edited by alexander; 05-15-2008 at 12:58 PM.. Reason: fixing the c code... was not working in the original version, all that well...
Reply With Quote
 
» Advertisement
» Current Poll
Who's the sexiest man alive? Johnny Depp or Robert Pattinson?
Johnny Depp - 30.00%
3 Votes
Robert Pattinson - 0%
0 Votes
Someone else (please specify) - 40.00%
4 Votes
I'm too macho to think a guy is sexy - 30.00%
3 Votes
Total Votes: 10
You may not vote on this poll.


All times are GMT -8. The time now is 08:10 AM.

Hypography?

Hypography [n.]: A combination of "hyperlink" and "bibliography" - ie, a list of links to electronic documents. Comparable to discography and bibliography, but not cartography.

We have been online since May 2000, and aim to be the best place to find and share science-related content of all kinds.

Share the love!

Please add more science to your life. Use our RSS feeds on your blog, your portal, or your favorite feedreader!


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright © 2000-2009 Hypography
Part of the Hypography - Science for Everyone Network