Don't believe us? Here, just look. This is an actual homework question that was inflicted upon someone in #bash.

(Warning: Do not try to solve this. Renicing every process on your system is likely to lead to bad outcomes. I can't even imagine what kind of person would ask their students to do such a thing.)

(a) DN3a.sh: Rabbit the Savior
Sometimes in live we wish that certain process runs as quick as possible. Here "Rabbit the Savior" that will take care of the selected processes, will come in handy. We select processes by providing a path to the process when we run Rabbit the Savior, together with some optional arguments. The Rabbit will then set priority p (default -10) to this group of processes and lower priority to all the other processes that are running on the system for s levels (default 2, ie. increase of value for 2). Rabbit the Savior must, in a case when less then n processes (default n=3) that we selected are running, run new instances up to the total number of n (with optional arguments if provided). If there are more than n processes running, we do not run any new process. If no instances of that program are running we run it up to the number n (with optional arguments, if provided). These new instance-running should be executed in a t-millisecond intervals (default 300). When the target number of instances is achieved, Rabbit the Savior ends its execution. Rabbit the Savior must output to the standard output time and message of its success: "Na tem mestu, <d>. <m>. 2019 je Zajec Veliki pomagal procesu <name of the process>.†(where day d in month m are without leading zeros).

When searching for the same processes, take into the account canonical paths to the programs, that were executed and ignore their arguments.

If we supply Rabbit the Savior with the argument with the path to the configuration file, it should read configuration from it. Each element of this configuration file is in its own line, where first key is written, followed by a semicolon and then the value of that setting. Order line-wise is not important, also every configuration element is optional. Configuration options:

log: path to the log file where everything that is being written to the standard output is logged (everything should also be written to the standard output),

n: number of instances of the target processes,

p: new level of niceness for the target processes,

s: level of niceness reduction for all the other processes,

t: time between separate instance creation in milliseconds.

An example of a call and an output, where default values are used:

> ./dn3a.sh /usr/bin/xeyes
Na tem mestu, 6. 5. je Zajec Veliki pomagal procesu /usr/bin/xeyes.
An example of a call, where configuration file korenje.conf is used and also arguments to the program are supplied:

> ./dn3a.sh "/bin/sleep infinity" korenje.conf
Na tem mestu, 6. 5. je Zajec Veliki pomagal procesu /bin/sleep.

BashFAQ/064/Examples (last edited 2019-05-20 17:30:08 by GreyCat)