CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/scripts/smc-nice-auto.py
Views: 687
1
#!/usr/bin/env python
2
import os, sys
3
4
passwd = [x.split(':') for x in open('/etc/passwd').readlines()]
5
6
7
def renice_user(user):
8
user = user.rstrip('+')
9
v = [x for x in passwd if user in x[2]]
10
if len(v) > 1:
11
print("user %s does not uniquely determine user" % user)
12
elif len(v) == 0:
13
print("no such user %s" % user)
14
else:
15
cmd = "sudo renice -n 19 -u %s" % v[0][0]
16
print(cmd)
17
os.system(cmd)
18
19
20
if len(sys.argv) > 1:
21
n = int(sys.argv[1])
22
else:
23
n = 5
24
25
users = {}
26
for x in os.popen("ps aux | sort -nrk 3,3").readlines():
27
v = x.split()
28
user = v[0]
29
if user not in ['root', 'salvus']:
30
users[user] = True
31
n -= 1
32
if n <= 0:
33
break
34
35
for user in users.keys():
36
renice_user(user)
37
38