#!/bin/bash function get_pids_to_restart { sudo lsof +c 0 / | \ awk '/DEL|(deleted)/ { print $2 }' | \ sort -u } function find_service_for_pid { systemctl status "$1" | \ awk '$2 ~ /\.service$/ && NR == 1 { print $2 }' } function is_cron_child { if [ "$1" != "cronie.service" ]; then return 1 fi if systemctl show cronie -p MainPID | grep -q "$2"; then return 1 fi return 0 } function echo_kill_pid { echo "sudo kill $1 # $(ps -p"$1" -o user=,cmd=)" } function echo_restart_service { echo "sudo systemctl restart $1" } for pid in $(get_pids_to_restart); do if [ "$pid" = 1 ]; then echo "sudo systemctl daemon-reexec" exit 0 fi service="$(find_service_for_pid "$pid")" if is_cron_child "$service" "$pid"; then echo_kill_pid "$pid" elif [ -n "$service" ]; then echo_restart_service "$service" else echo_kill_pid "$pid" fi done | sort -u