Skip to main content

A greedy processes killer

Tania is a python program designed to kill processes that should not be there on a server hosting many users sessions, like a computing cluster's frontend, generally because users forgot (or do not know how to) launch their program into a proper job. You can customize which processes should be monitored (targets) and which should be whitelisted (allies), based on their name, owner, cputime and memory size (rss). Tania is designed to be run as a cron job and can send e-mails to the users having their processes shot down. A warning threshold can be set-up before the actual kill to send a warning e-mail.

Installation

Install tania:

git clone https://github.com/bzizou/tania
cd tania
pip install .

Copy etc/tania.conf and etc/tania_targets.json to an appropriate location, for example /etc, and customize those files. You can set up the $TANIA_CONF_FILE variable if you placed the config file into another location than /etc.

sudo cp etc/tania.conf /etc
sudo cp etc/tania_targets.json /etc
# Edit tania.conf and tania_targets.json
# WARNING: tania can kill system processes if not configured properly!

Usage

~# tania --help
Usage: tania [options]

Options:
  -h, --help     show this help message and exit
  -D, --do       Actualy do kill bad processes
  -v, --verbose  Be more verbose
  -m, --mail     Send an email to the familly of the deceased

By default, tania does nothing and only prints the PID of the processes that should be killed:

~# tania               
Warning: 1827444 is in the viewfinder 
Warning: 210765 is in the viewfinder  
Warning: 3317806 is in the viewfinder 

You can print more informations, to know the reasons of the kills:

~# tania -v
We should kill 1670118 ( yes ) of bzizou with cputime 4 (limit  1 )
We should kill 1666340 ( stress-ng-vm [run] ) of bzizou with memory 212292 (limit  200000 )

To actually kill the processes, use --do:

~# tania --do
Shooting down process 1670118

The --mail option will send an e-mail to the owner of the killed process using the mail templates from the config file.

Finally, Tania is meant to be run frequently from cron. Here's an example cron job configuration:

# cat /etc/cron.d/tania                                  
*/2 * * * * root /usr/local/bin/tania --do --mail |grep -v Warning

Configuring targets

The tania.conf file is self-explanatory; just follow the comments.

The json targets file (tania_targets.json by default) contains 2 types of entries: ally or target. An ally is simply a process that should never be killed.

Targets and allies are defined by a cmd and a user string. Those strings are regular expressions.

Here's an ally example meaning that all Nextflow processes of the user Goldorak should never be killed:

{
    "type": "ally",
    "cmd": "^.*nextflow.*",
    "user": "goldorak"
},

Targets have time_limit, time_limit_warn and rss_limit definitions.

  • time_limit: Max CPU time in seconds at which a process should be killed
  • time_limit_warn: CPU time in seconds at which warning e-mail should be sent to the user
  • rss_limit: Max memory limit that a process can use before being killed

Here's a default configuration to kill every processes that use more than 600s of cpu time with a warning at 300s of cpu time, and maximum memory use of 1GB:

{
     "type": "target",
     "cmd": ".*",
     "user": ".*",
     "time_limit": 600,
     "time_limit_warn": 300,
     "rss_limit": 1000000
}

WARNING: You should generally keep all system processes as ally with such an entry:

{
    "type": "ally",
    "cmd": ".*",
    "user": "^root$|^postgres$|^apache2$|^avahi$|^messagebus$|^polkituser$|^systemd.*|^rtkit$|^openldap$|^oar$|^bind$|^nut$|^www-data$|^flexlm$|^ntp$|^statd$|^oident$|^nslcd$|^nscd$|^haldaemon$|^munge$|^dbus$|^rpc$|^_fluentd$|^calyptia-fluent$"
},

Add more users to the list if necessary.

Why this name "Tania" ?

Check https://en.wikipedia.org/wiki/Tania_Chernova

Release files for tania 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tania 1.0.2
File Size Uploaded
tania-1.0.2.tar.gz 19.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tania 1.0.2
File Interpreter ABI Platform
tania-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 38.0 kB

Release files / tania-1.0.2.tar.gz

Download URL tania-1.0.2.tar.gz
Size 19.0 kB
Tags Source
SHA-256 checksum
How to use checksums
3b7da3b837e11e5132c07283eda50a5bf9e7a719ba77f76f756370771a901e5f
BLAKE2b-256 checksum
How to use checksums
9cca0803a84b5e78ab14abad41d4f22faec839ba8843cf45ee8b62f3404374fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.3

Release files / tania-1.0.2-py3-none-any.whl

Download URL tania-1.0.2-py3-none-any.whl
Size 19.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5569c98ea7dc252c71063d589a3bd16f12244d8ae83b1d17d7494914fcb25a75
BLAKE2b-256 checksum
How to use checksums
0d73dbd09ebd085f8fa9d6b0bb694b5880ade0e45f42479d18ff9874e2bfc86b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.3

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page