fix readme and output

This commit is contained in:
Alexey Avramov 2019-03-04 02:50:54 +09:00
parent 1b27ce2833
commit 0e1bed33e7
2 changed files with 29 additions and 4 deletions

View File

@ -34,6 +34,10 @@ Also look at [Why are low memory conditions handled so badly?](https://www.reddi
The tools listed above may work at the same time on one computer. The tools listed above may work at the same time on one computer.
### See also
- `memlockd` - daemon to lock files in memory with mlock. It is used to lock system programs and config files in memory so that if a DOS attack is experienced then the chance of the sys-admin regaining control of the system in a reasonable amount of time (and therefore having a reasonable chance of discovering the cause of the problem) is significantly increased.
## Some features ## Some features
- Sending the SIGTERM signal is default corrective action. If the victim does not respond to SIGTERM, with a further drop in the level of memory it gets SIGKILL. - Sending the SIGTERM signal is default corrective action. If the victim does not respond to SIGTERM, with a further drop in the level of memory it gets SIGKILL.

29
nohang
View File

@ -50,6 +50,13 @@ HR = ''
victim_dict = dict() victim_dict = dict()
extra_process_table_info = None
########################################################################## ##########################################################################
# define functions # define functions
@ -124,11 +131,11 @@ def update_stat_dict_and_print(key):
if print_total_stat: if print_total_stat:
stats_msg = '{}\nWhat happened in the last {}:'.format( stats_msg = '{}\nTotal stat (what happened in the last {}):'.format(
HR, format_time(time() - start_time)) HR, format_time(time() - start_time))
for i in stat_dict: for i in stat_dict:
stats_msg += '\n- {}: {}'.format(i, stat_dict[i]) stats_msg += '\n {}: {}'.format(i, stat_dict[i])
print(stats_msg) print(stats_msg)
@ -395,6 +402,18 @@ def pid_to_cmdline(pid):
return f.read().replace('\x00', ' ').rstrip() return f.read().replace('\x00', ' ').rstrip()
def pid_to_realpath(pid):
try:
return os.path.realpath('/proc/' + pid + '/exe')
except FileNotFoundError:
return ''
def pid_to_uid(pid): def pid_to_uid(pid):
'''return euid''' '''return euid'''
try: try:
@ -661,7 +680,9 @@ def find_victim():
str(badness).rjust(7), str(badness).rjust(7),
pid_to_name(pid).ljust(15), pid_to_name(pid).ljust(15),
pid_to_uid(pid).rjust(10), pid_to_uid(pid).rjust(10),
pid_to_cmdline(pid)) pid_to_cmdline(pid)
# pid_to_realpath(pid)
)
) )
pid_badness_list.append((pid, badness)) pid_badness_list.append((pid, badness))
@ -974,7 +995,7 @@ def implement_corrective_action(signal):
round(response_time * 1000)) round(response_time * 1000))
preventing_oom_message = '\nImplement a corrective action:' \ preventing_oom_message = '\nImplement a corrective action:' \
'\n Send {} to the victim; {}'.format( '\n Send {} to the victim; {}'.format(
sig_dict[signal], send_result) sig_dict[signal], send_result)
key = 'Send {} to {}'.format( key = 'Send {} to {}'.format(