Wednesday, 9 September 2015

PR(08) C / C++ Program to assign nice values to processes and dynamically monitor them



#include<stdlib.h>
#include<stdio.h>
#include<sys/resource.h>
#include<unistd.h>
int main()
{
    int rc,nc;
    int ch;
    while(1)
    {
system("ps axl");
printf("\nCurrent nice vale can be checked from above table");
printf("\nThe Current priority of the process %d is %d",getpid(),getpriority(PRIO_PROCESS,0));
printf("\nEnter new nice value(between -20 to 20)");
scanf("%d",&nc);
rc=setpriority(PRIO_PROCESS,0,nc);
if(0!=rc)
{
perror("setpriority");
}
sleep(2);
printf("Modified nice value of the process%d is:%d",getpid(),getpriority(PRIO_PROCESS,0));
printf("Do you want to continue(1 continue or 0 stop):");
scanf("%d",&ch);
if(ch==0)
exit(0);
}
return 0;
}

No comments:

Post a Comment