If you're using systemd, you can set some additional options in a .service
file. The complete list of the options you can set is described here.
Below is a short example that shows how to use this feature of systemd:
# cat /etc/systemd/system/qbittorrent-nox.service
[Unit]
Description=qbittorrent-nox
Documentation=man:qbittorrent-nox
DefaultDependencies=yes
Requires=media-Kabi.mount
After=media-Kabi.mount network-online.target
Before=multi-user.target
Conflicts=umount.target
[Service]
User=morfik
Group=p2p
Type= simple
RemainAfterExit=no
ExecStart=/usr/bin/qbittorrent-nox
Nice=19
IOSchedulingClass=idle
PrivateNetwork=no
CPUShares=256
MemoryLimit=50M
BlockIOWeight=128
Slice=p2p.slice
StandardError=null
StandardOutput=null
[Install]
WantedBy=multi-user.target
Of course, you don't need all of the options I used. If you just want to limit memory usage, add MemoryLimit=50M
, which limits to 50MiB.
And this is the result:
# systemctl status qbittorrent-nox.service
● qbittorrent-nox.service - qbittorrent-nox
Loaded: loaded (/etc/systemd/system/qbittorrent-nox.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2015-05-07 19:25:20 CEST; 1s ago
Docs: man:qbittorrent-nox
Main PID: 21712 (qbittorrent-nox)
Memory: 9.4M (limit: 50.0M)
CGroup: /p2p.slice/qbittorrent-nox.service
└─21712 /usr/bin/qbittorrent-nox
May 07 19:25:20 morfikownia systemd[1]: Started qbittorrent-nox.
May 07 19:25:20 morfikownia systemd[1]: Starting qbittorrent-nox...
So far, this works only for system daemons/services, and you can't limit, for instance, a firefox processes as a regular user in this way. But maybe this will change some day.
valgrind
.