Sponsored Content
Top Forums Shell Programming and Scripting How to run a process when the computer is idle? Post 302354953 by pludi on Monday 21st of September 2009 04:44:37 AM
Old 09-21-2009
There's a small logical error in your example: nice only advises the process scheduler, and a high niceness doesn't mean that the process will wait 'till nothing else is running. It just means that those processes with a lower niceness will run first, and after they're done or waiting it'll get CPU time just like the others.
Besides, the example you've given is probably more influenced by I/O waits of 2 (or more) processes accessing the HDD than the scheduler.

As for your problem, you could check the first or second field of /proc/loadavg (1 / 5 minute load average), and depending on that start your process. It can't, however, predict whether or not another, CPU intensive, process will start just 5 seconds after.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to run a script when your computer is idle

I am trying to run a script that I made when my computer is idle. How do I go about doing this. Thanks :) (4 Replies)
Discussion started by: rehansaeed
4 Replies

2. Shell Programming and Scripting

finding idle time of a process

Matez, I have a list of process id's in a text file. I want to know how to find the idle time of a process which are more than 300secs and kill them accordingly. Could you please help me to get these details. I want to write a shell script with this. Thanks..Krish :) (36 Replies)
Discussion started by: Krrishv
36 Replies

3. UNIX for Dummies Questions & Answers

How to see if the process is idle

We are running AIX 5.3 and for ICICS Printing we have process called cicstermp runing whcih attaches the print to print queue But is process is triggered when ever a print is to be given Can we find the processes which are idle I mean every time a print is given it creats a new cicstermp... (1 Reply)
Discussion started by: pbsrinivas
1 Replies

4. Shell Programming and Scripting

How to kill process after x idle min?

I need a script to kill those process id whose idle time is more than 30min plz help me (3 Replies)
Discussion started by: salil2012
3 Replies

5. AIX

Kill IDLE Process using script !!!

Dear Friends , I am using DB2 database in AIX 5.3 server . In my server some IDLE process are generated after several times which I need to kill it manually each and every time . The process I query like following : root@bagpuss $ ps auxw|sort -r +3|head -10 USER PID %CPU %MEM ... (3 Replies)
Discussion started by: shipon_97
3 Replies

6. Solaris

Why CPU idle 0 process nohub lose

Hello Solaris 8 when CPU idle 0 . why nohub process lose ? Thank (1 Reply)
Discussion started by: ppmanja
1 Replies

7. UNIX for Advanced & Expert Users

idle% cpu and run queue

Hi Everybody, Can anybody explain how CPU idle% is about 50%, but runq-sz more than 1? sar from Solaris 10: 00:00:05 %usr %sys %wio %idle 17:00:08 27 12 0 61 17:20:05 40 15 0 45 17:40:05 27 12 0 61 18:00:05 23... (2 Replies)
Discussion started by: sant
2 Replies

8. Shell Programming and Scripting

Kill idle Process using a script

Hi, I need a script that can automatically kill all processes named "webrepn" and "webrebw" if idle for more than 30 minutes. Then I will have a Cron Job to run the script every night or 2-3 times a day depends on how this script helps. Right now, I run "ps -ef | grep webrebn" and "kill -9... (7 Replies)
Discussion started by: MaggieL
7 Replies

9. UNIX for Dummies Questions & Answers

Idle Process Exhausting CPU

I noticed when having some trouble with code I was testing that the CPU was becoming exhausted and I would have to reboot. After rebooting a couple times I decided to check for other problems before trying my code again. That's when I noticed that the CPU with the idle process was through the roof:... (5 Replies)
Discussion started by: Azrael
5 Replies

10. Shell Programming and Scripting

Activate command when computer is idle

I would like to run a command if my computer is idle. I found this, but is not quite working. #!/bin/sh idletime=$(xprintidle) threshold=300000 # 5 min = 5 * 60 * 1000 ms if ; then echo "idle for 5 minutes." fi (4 Replies)
Discussion started by: drew77
4 Replies
SCHEDULER(9)						   BSD Kernel Developer's Manual					      SCHEDULER(9)

NAME
curpriority_cmp, maybe_resched, resetpriority, roundrobin, roundrobin_interval, sched_setup, schedclock, schedcpu, setrunnable, updatepri -- perform round-robin scheduling of runnable processes SYNOPSIS
#include <sys/param.h> #include <sys/proc.h> int curpriority_cmp(struct proc *p); void maybe_resched(struct thread *td); void propagate_priority(struct proc *p); void resetpriority(struct ksegrp *kg); void roundrobin(void *arg); int roundrobin_interval(void); void sched_setup(void *dummy); void schedclock(struct thread *td); void schedcpu(void *arg); void setrunnable(struct thread *td); void updatepri(struct thread *td); DESCRIPTION
Each process has three different priorities stored in struct proc: p_usrpri, p_nativepri, and p_priority. The p_usrpri member is the user priority of the process calculated from a process' estimated CPU time and nice level. The p_nativepri member is the saved priority used by propagate_priority(). When a process obtains a mutex, its priority is saved in p_nativepri. While it holds the mutex, the process's priority may be bumped by another process that blocks on the mutex. When the process releases the mutex, then its priority is restored to the priority saved in p_nativepri. The p_priority member is the actual priority of the process and is used to determine what runqueue(9) it runs on, for example. The curpriority_cmp() function compares the cached priority of the currently running process with process p. If the currently running process has a higher priority, then it will return a value less than zero. If the current process has a lower priority, then it will return a value greater than zero. If the current process has the same priority as p, then curpriority_cmp() will return zero. The cached priority of the currently running process is updated when a process resumes from tsleep(9) or returns to userland in userret() and is stored in the private variable curpriority. The maybe_resched() function compares the priorities of the current thread and td. If td has a higher priority than the current thread, then a context switch is needed, and KEF_NEEDRESCHED is set. The propagate_priority() looks at the process that owns the mutex p is blocked on. That process's priority is bumped to the priority of p if needed. If the process is currently running, then the function returns. If the process is on a runqueue(9), then the process is moved to the appropriate runqueue(9) for its new priority. If the process is blocked on a mutex, its position in the list of processes blocked on the mutex in question is updated to reflect its new priority. Then, the function repeats the procedure using the process that owns the mutex just encountered. Note that a process's priorities are only bumped to the priority of the original process p, not to the priority of the previously encountered process. The resetpriority() function recomputes the user priority of the ksegrp kg (stored in kg_user_pri) and calls maybe_resched() to force a reschedule of each thread in the group if needed. The roundrobin() function is used as a timeout(9) function to force a reschedule every sched_quantum ticks. The roundrobin_interval() function simply returns the number of clock ticks in between reschedules triggered by roundrobin(). Thus, all it does is return the current value of sched_quantum. The sched_setup() function is a SYSINIT(9) that is called to start the callout driven scheduler functions. It just calls the roundrobin() and schedcpu() functions for the first time. After the initial call, the two functions will propagate themselves by registering their call- out event again at the completion of the respective function. The schedclock() function is called by statclock() to adjust the priority of the currently running thread's ksegrp. It updates the group's estimated CPU time and then adjusts the priority via resetpriority(). The schedcpu() function updates all process priorities. First, it updates statistics that track how long processes have been in various process states. Secondly, it updates the estimated CPU time for the current process such that about 90% of the CPU usage is forgotten in 5 * load average seconds. For example, if the load average is 2.00, then at least 90% of the estimated CPU time for the process should be based on the amount of CPU time the process has had in the last 10 seconds. It then recomputes the priority of the process and moves it to the appropriate runqueue(9) if necessary. Thirdly, it updates the %CPU estimate used by utilities such as ps(1) and top(1) so that 95% of the CPU usage is forgotten in 60 seconds. Once all process priorities have been updated, schedcpu() calls vmmeter() to update various other sta- tistics including the load average. Finally, it schedules itself to run again in hz clock ticks. The setrunnable() function is used to change a process's state to be runnable. The process is placed on a runqueue(9) if needed, and the swapper process is woken up and told to swap the process in if the process is swapped out. If the process has been asleep for at least one run of schedcpu(), then updatepri() is used to adjust the priority of the process. The updatepri() function is used to adjust the priority of a process that has been asleep. It retroactively decays the estimated CPU time of the process for each schedcpu() event that the process was asleep. Finally, it calls resetpriority() to adjust the priority of the process. SEE ALSO
mi_switch(9), runqueue(9), sleepqueue(9), tsleep(9) BUGS
The curpriority variable really should be per-CPU. In addition, maybe_resched() should compare the priority of chk with that of each CPU, and then send an IPI to the processor with the lowest priority to trigger a reschedule if needed. Priority propagation is broken and is thus disabled by default. The p_nativepri variable is only updated if a process does not obtain a sleep mutex on the first try. Also, if a process obtains more than one sleep mutex in this manner, and had its priority bumped in between, then p_nativepri will be clobbered. BSD
November 3, 2000 BSD
All times are GMT -4. The time now is 02:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy