Hi,
I am running a fully updated F23 box but this question does not have much to do with Fedora itself, hence the designator and the disclaimer.
I am wanting to run a script which will look at all the jobs that are running and renice all of them which have been on for more than five minutes. (Then I can run the script as a cron job as root and be done with automating the process.)
Are there any suggestions as to how to go about this task efficiently? Actually, before I reinvent the wheel, are there any standard options that already exist and which would be more suitable for me than just to do everything from scratch.
Best wishes, Ranjan
On 02/22/2016 10:19 AM, Ranjan Maitra wrote:
Hi,
I am running a fully updated F23 box but this question does not have much to do with Fedora itself, hence the designator and the disclaimer.
I am wanting to run a script which will look at all the jobs that are running and renice all of them which have been on for more than five minutes. (Then I can run the script as a cron job as root and be done with automating the process.)
Are there any suggestions as to how to go about this task efficiently? Actually, before I reinvent the wheel, are there any standard options that already exist and which would be more suitable for me than just to do everything from scratch.
Use the "-o pid,etimes=" options of ps to get the elapsed time of tasks in seconds. To get a full list, for example, as root:
ps ax -o pid,uid,etimes= ... 21412 0 833 21499 0 631433 21541 0 773 21597 1000 769 21604 1000 769 21605 1000 769 21608 1000 769 21610 1000 769 21613 1000 769 21681 1000 769 21686 1000 769 21697 1000 769 21751 1000 742 ...
(run it as root so you can see ALL of the processes)
As you can see, you get three columns: the first is the PID of the task, the second is the EUID of the user running it, and the third is the elapsed time.
So, pull that data into a shell array, look for stuff that has the second column equal to the user ID you're interested in and the third column >= 300 seconds and renice the PID in the first column. Note that I'd avoid renicing any tasks with UIDs < your lowest normal user ID (typically 100) to keep from starving system tasks.
Hope that helps! ---------------------------------------------------------------------- - Rick Stevens, Systems Engineer, AllDigital ricks@alldigital.com - - AIM/Skype: therps2 ICQ: 226437340 Yahoo: origrps2 - - - - "And on the seventh day, He exited from append mode." - ----------------------------------------------------------------------
On Mon, 22 Feb 2016 10:38:30 -0800 Rick Stevens ricks@alldigital.com wrote:
On 02/22/2016 10:19 AM, Ranjan Maitra wrote:
Hi,
I am running a fully updated F23 box but this question does not have much to do with Fedora itself, hence the designator and the disclaimer.
I am wanting to run a script which will look at all the jobs that are running and renice all of them which have been on for more than five minutes. (Then I can run the script as a cron job as root and be done with automating the process.)
Are there any suggestions as to how to go about this task efficiently? Actually, before I reinvent the wheel, are there any standard options that already exist and which would be more suitable for me than just to do everything from scratch.
Use the "-o pid,etimes=" options of ps to get the elapsed time of tasks in seconds. To get a full list, for example, as root:
ps ax -o pid,uid,etimes= ... 21412 0 833 21499 0 631433 21541 0 773 21597 1000 769 21604 1000 769 21605 1000 769 21608 1000 769 21610 1000 769 21613 1000 769 21681 1000 769 21686 1000 769 21697 1000 769 21751 1000 742 ...
(run it as root so you can see ALL of the processes)
As you can see, you get three columns: the first is the PID of the task, the second is the EUID of the user running it, and the third is the elapsed time.
So, pull that data into a shell array, look for stuff that has the second column equal to the user ID you're interested in and the third column >= 300 seconds and renice the PID in the first column. Note that I'd avoid renicing any tasks with UIDs < your lowest normal user ID (typically 100) to keep from starving system tasks.
Hope that helps!
Yes, this absolutely helps, thanks!! But is there a 2-d array in bash (or do we do array of arrays)? (I am presuming that I need to store this in a 2-d array and then look at columns 2 and 3 and renice the PIDs in column 1.) Also, how does one assign the output of the ps to a 2-d array?
Many thanks again and best wishes! Ranjan
____________________________________________________________ FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop! Check it out at http://www.inbox.com/marineaquarium
On 02/22/2016 10:50 AM, Ranjan Maitra wrote:
On Mon, 22 Feb 2016 10:38:30 -0800 Rick Stevens ricks@alldigital.com wrote:
On 02/22/2016 10:19 AM, Ranjan Maitra wrote:
Hi,
I am running a fully updated F23 box but this question does not have much to do with Fedora itself, hence the designator and the disclaimer.
I am wanting to run a script which will look at all the jobs that are running and renice all of them which have been on for more than five minutes. (Then I can run the script as a cron job as root and be done with automating the process.)
Are there any suggestions as to how to go about this task efficiently? Actually, before I reinvent the wheel, are there any standard options that already exist and which would be more suitable for me than just to do everything from scratch.
Use the "-o pid,etimes=" options of ps to get the elapsed time of tasks in seconds. To get a full list, for example, as root:
ps ax -o pid,uid,etimes= ... 21412 0 833 21499 0 631433 21541 0 773 21597 1000 769 21604 1000 769 21605 1000 769 21608 1000 769 21610 1000 769 21613 1000 769 21681 1000 769 21686 1000 769 21697 1000 769 21751 1000 742 ...
(run it as root so you can see ALL of the processes)
As you can see, you get three columns: the first is the PID of the task, the second is the EUID of the user running it, and the third is the elapsed time.
So, pull that data into a shell array, look for stuff that has the second column equal to the user ID you're interested in and the third column >= 300 seconds and renice the PID in the first column. Note that I'd avoid renicing any tasks with UIDs < your lowest normal user ID (typically 100) to keep from starving system tasks.
Hope that helps!
Yes, this absolutely helps, thanks!! But is there a 2-d array in bash (or do we do array of arrays)? (I am presuming that I need to store this in a 2-d array and then look at columns 2 and 3 and renice the PIDs in column 1.) Also, how does one assign the output of the ps to a 2-d array?
Uhm, no. You can simulate them using associative arrays, but it gets rather hairy. You may want to try something like awk or PHP or Perl to do this more easily.
---------------------------------------------------------------------- - Rick Stevens, Systems Engineer, AllDigital ricks@alldigital.com - - AIM/Skype: therps2 ICQ: 226437340 Yahoo: origrps2 - - - - Memory is the second thing to go, but I can't remember the first! - ----------------------------------------------------------------------
On Mon, 22 Feb 2016 10:58:53 -0800 Rick Stevens ricks@alldigital.com wrote:
On 02/22/2016 10:50 AM, Ranjan Maitra wrote:
On Mon, 22 Feb 2016 10:38:30 -0800 Rick Stevens ricks@alldigital.com wrote:
On 02/22/2016 10:19 AM, Ranjan Maitra wrote:
Hi,
I am running a fully updated F23 box but this question does not have much to do with Fedora itself, hence the designator and the disclaimer.
I am wanting to run a script which will look at all the jobs that are running and renice all of them which have been on for more than five minutes. (Then I can run the script as a cron job as root and be done with automating the process.)
Are there any suggestions as to how to go about this task efficiently? Actually, before I reinvent the wheel, are there any standard options that already exist and which would be more suitable for me than just to do everything from scratch.
Use the "-o pid,etimes=" options of ps to get the elapsed time of tasks in seconds. To get a full list, for example, as root:
ps ax -o pid,uid,etimes= ... 21412 0 833 21499 0 631433 21541 0 773 21597 1000 769 21604 1000 769 21605 1000 769 21608 1000 769 21610 1000 769 21613 1000 769 21681 1000 769 21686 1000 769 21697 1000 769 21751 1000 742 ...
(run it as root so you can see ALL of the processes)
As you can see, you get three columns: the first is the PID of the task, the second is the EUID of the user running it, and the third is the elapsed time.
So, pull that data into a shell array, look for stuff that has the second column equal to the user ID you're interested in and the third column >= 300 seconds and renice the PID in the first column. Note that I'd avoid renicing any tasks with UIDs < your lowest normal user ID (typically 100) to keep from starving system tasks.
Hope that helps!
Yes, this absolutely helps, thanks!! But is there a 2-d array in bash (or do we do array of arrays)? (I am presuming that I need to store this in a 2-d array and then look at columns 2 and 3 and renice the PIDs in column 1.) Also, how does one assign the output of the ps to a 2-d array?
Uhm, no. You can simulate them using associative arrays, but it gets rather hairy. You may want to try something like awk or PHP or Perl to do this more easily.
OK, thanks! I guess i will have to figure out one of awk, etc then. Separately, I have realized that I should also output nice as part of the ps options because there is no point in renicing jobs that are already niced.
Best wishes, Ranjan
____________________________________________________________ FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop! Check it out at http://www.inbox.com/earth
On 2/22/2016 1:50 PM, Ranjan Maitra wrote:
On Mon, 22 Feb 2016 10:38:30 -0800 Rick Stevens ricks@alldigital.com wrote:
On 02/22/2016 10:19 AM, Ranjan Maitra wrote:
Hi,
I am running a fully updated F23 box but this question does not have much to do with Fedora itself, hence the designator and the disclaimer.
I am wanting to run a script which will look at all the jobs that are running and renice all of them which have been on for more than five minutes. (Then I can run the script as a cron job as root and be done with automating the process.)
Are there any suggestions as to how to go about this task efficiently? Actually, before I reinvent the wheel, are there any standard options that already exist and which would be more suitable for me than just to do everything from scratch.
Use the "-o pid,etimes=" options of ps to get the elapsed time of tasks in seconds. To get a full list, for example, as root:
ps ax -o pid,uid,etimes= ... 21412 0 833 21499 0 631433 21541 0 773 21597 1000 769 21604 1000 769 21605 1000 769 21608 1000 769 21610 1000 769 21613 1000 769 21681 1000 769 21686 1000 769 21697 1000 769 21751 1000 742 ...
(run it as root so you can see ALL of the processes)
As you can see, you get three columns: the first is the PID of the task, the second is the EUID of the user running it, and the third is the elapsed time.
So, pull that data into a shell array, look for stuff that has the second column equal to the user ID you're interested in and the third column >= 300 seconds and renice the PID in the first column. Note that I'd avoid renicing any tasks with UIDs < your lowest normal user ID (typically 100) to keep from starving system tasks.
Hope that helps!
Yes, this absolutely helps, thanks!! But is there a 2-d array in bash (or do we do array of arrays)? (I am presuming that I need to store this in a 2-d array and then look at columns 2 and 3 and renice the PIDs in column 1.) Also, how does one assign the output of the ps to a 2-d array?
Many thanks again and best wishes! Ranjan
FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop! Check it out at http://www.inbox.com/marineaquarium
I would use a little bash script: #!/bin/bash
while read pid uid etime nice; do echo "pid=$pid uid=$uid etime=$etime nice=$nice" done < <(ps ax -o pid,uid,etimes=,nice)
Bill
On Mon, 22 Feb 2016 10:38:30 -0800 Rick Stevens ricks@alldigital.com wrote:
On 02/22/2016 10:19 AM, Ranjan Maitra wrote:
Hi,
I am running a fully updated F23 box but this question does not have much to do with Fedora itself, hence the designator and the disclaimer.
I am wanting to run a script which will look at all the jobs that are running and renice all of them which have been on for more than five minutes. (Then I can run the script as a cron job as root and be done with automating the process.)
Are there any suggestions as to how to go about this task efficiently? Actually, before I reinvent the wheel, are there any standard options that already exist and which would be more suitable for me than just to do everything from scratch.
Use the "-o pid,etimes=" options of ps to get the elapsed time of tasks in seconds. To get a full list, for example, as root:
ps ax -o pid,uid,etimes= ... 21412 0 833 21499 0 631433 21541 0 773 21597 1000 769 21604 1000 769 21605 1000 769 21608 1000 769 21610 1000 769 21613 1000 769 21681 1000 769 21686 1000 769 21697 1000 769 21751 1000 742 ...
(run it as root so you can see ALL of the processes)
As you can see, you get three columns: the first is the PID of the task, the second is the EUID of the user running it, and the third is the elapsed time.
So, pull that data into a shell array, look for stuff that has the second column equal to the user ID you're interested in and the third column >= 300 seconds and renice the PID in the first column. Note that I'd avoid renicing any tasks with UIDs < your lowest normal user ID (typically 100) to keep from starving system tasks.
Hope that helps!
Yes, this absolutely helps, thanks!! But is there a 2-d array in bash (or do we do array of arrays)? (I am presuming that I need to store this in a 2-d array and then look at columns 2 and 3 and renice the PIDs in column 1.) Also, how does one assign the output of the ps to a 2-d array?
Many thanks again and best wishes! Ranjan
____________________________________________________________ FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop! Check it out at http://www.inbox.com/earth