MCPcopy Create free account
hub / github.com/bleachbit/bleachbit / make_self_oom_target_linux

Function make_self_oom_target_linux

bleachbit/Memory.py:108–126  ·  view source on GitHub ↗

Make the current process the primary target for Linux out-of-memory killer

()

Source from the content-addressed store, hash-verified

106
107
108def make_self_oom_target_linux():
109 """Make the current process the primary target for Linux out-of-memory killer"""
110 path = f'/proc/{os.getpid()}/oom_score_adj'
111 if os.path.exists(path):
112 with open(path, 'w', encoding='utf-8') as f:
113 f.write('1000')
114 # OOM likes nice processes
115 logger.debug(_("Setting nice value %d for this process."), os.nice(19))
116 # OOM prefers non-privileged processes
117 try:
118 uid = General.get_real_uid()
119 if uid > 0:
120 # TRANSLATORS: Debug message when a process gives up root/admin privileges.
121 # %(pid)d is the integer process ID; %(uid)d is the integer user ID to switch to.
122 drop_msg = _("Dropping privileges of process ID %(pid)d to user ID %(uid)d.")
123 logger.debug(drop_msg, {'pid': os.getpid(), 'uid': uid})
124 os.seteuid(uid)
125 except:
126 logger.exception('Error when dropping privileges')
127
128
129def fill_memory_linux():

Callers 2

wipe_memoryFunction · 0.85

Calls 1

writeMethod · 0.45

Tested by 1