Giter Club home page Giter Club logo

Comments (17)

lopadova avatar lopadova commented on July 17, 2024

Hi @Betaman2k ,
normally you must set the MAX_SEC2 var greater than MAX_SEC.

The script check 2 condition to kill process:

  1. (CPU% > MAX_CPU) AND (process_execution_time > $MAX_SEC)
    ex.:
    MAX_CPU=90
    MAX_SEC=10
    if the CPU percentage greater than 90% AND process time greater than 10 seconds
    process was killed.
    if the CPU percentage greater than 90% but process time NOT greater than 10 seconds
    process was NOT killed.

  2. (process_execution_time > $MAX_SEC2)
    ex.:
    MAX_SEC2=5
    if the process time greater than 5 seconds process was killed (for any CPU percentage)

from kill-process.

Betaman2k avatar Betaman2k commented on July 17, 2024

Hi
yeah i understand this option, but he killing nothing, dunno why
my cpu load ( process ) was 1+ hour 95+ % but he killing nothing

perhaps any problem with the crontab, check every minute ?

bash /root/myscript/kill-process/killprocess.sh kill top cpu > /var/log/killprocess.log 2>&1

i use only one crontab with this cmd

logfile.

Process execute in 'kill' mode.
Process fetched by 'top' command
Process sort by %CPU ( 9 )
Check /usr/bin/tor process...
There isn't any matched process for /usr/bin/tor

cya
betaman

from kill-process.

lopadova avatar lopadova commented on July 17, 2024

ok.

try these:

  1. run top in console and ensure the process name is: exactely /usr/bin/tor
    if not, set KILLLIST to right process name.

if you don't resolve:
2) are you run the cron or command with root user?
if you exec bash script by root remember to set this var to empty string:
EXCLUDE_ROOT=""

if you don't resolve:
3) try to run batch manually in shell (not cron) with normal user (not root) and look if the message is the same.

if you don't resolve:
4) try to run in shell this command:
top -bcSH -n 1 | grep /usr/bin/tor | sort -k 9 -r | head -n 1 | awk '{print $1}'
and look if the command return an number (process ID) or not.

best regards,
Lorenzo.

from kill-process.

Betaman2k avatar Betaman2k commented on July 17, 2024

Heya

cmd works perfect: top -bcSH -n 1 | grep tor | sort -k 9 -r | head -n 1 | awk '{print $1}'
now tor was 100 % cpu load 1-2 hours, this script dont kill the process, dunno why.

my config:

#process command name to check
declare -a KILLLIST
KILLLIST=("tor")
#email (if empty no email will sent)
EMAIL=""
#max cpu % load
MAX_CPU=90
#max execution time for CPU percentage > MAX_CPU (in seconds 7200s=2h)
MAX_SEC=20
#max execution time for any %CPU (in seconds 2700s=45min)
MAX_SEC2=30
#exclude root process (leave empty for match root process too)
EXCLUDE_ROOT=""

my crontab check every 2 minutes: bash /root/myscript/kill-process/killprocess.sh kill top cpu > /var/log/killprocess.log 2>&1

perhaps my crontab is wrong ?
i used only the kill modus ?

i check ur install.sh ( crontab ) and i see u used time cmd too

echo "0 * * * * bash /root/myscript/kill-process/killprocess.sh kill top cpu > /var/log/killprocess.log 2>&1" >> mycron
echo "5 * * * * bash /root/myscript/kill-process/killprocess.sh kill top cpu > /var/log/killprocess.log 2>&1" >> mycron
echo "15 * * * * bash /root/myscript/kill-process/killprocess.sh kill top time > /var/log/killprocess.log 2>&1" >> mycron
echo "30 * * * * bash /root/myscript/kill-process/killprocess.sh kill top cpu > /var/log/killprocess.log 2>&1" >> mycron
echo "45 * * * * bash /root/myscript/kill-process/killprocess.sh kill top time > /var/log/killprocess.log 2>&1" >> mycron

cya
Betaman

from kill-process.

lopadova avatar lopadova commented on July 17, 2024

Hi @Betaman2k
if I understand you have this situation:

  1. if you run bash kill-process.sh form cmd => all works fine, and the process was killed.
  2. if you run process.sh from cron => don't works and if you look into log you will see "No Process kill, CPU load 100 %"?

Check if the cron was execute with the same user you use with cmd session? or cron was executed with other user / other permission?

If the condition 1) and 2) is right,
try to schedule cron with this command and look into log:
top -bcSH -n 1 | grep tor | sort -k 9 -r | head -n 1
what process (and what cpu%) do you see in the log?
try this cmd too:
top -bcSH -n 1 | grep tor | sort -k 9 -r
can you see the tor process you find?

Best Regards.
Lorenzo.

from kill-process.

Betaman2k avatar Betaman2k commented on July 17, 2024

Heya

no only this cmd works perfect
Infos:
top -bcSH -n 1 | grep tor | sort -k 9 -r | head -n 1 | awk '{print $1}' = 26374

top -bcSH -n 1 | grep tor | sort -k 9 -r | head -n 1 = 26374 debian-+ 20 0 241476 195268 13180 S 18.3 1.2 542:52.02 /usr/bin/tor --defaults-torrc /usr/share/tor/tor-service-defaults-torrc -f /etc/tor/torrc --RunAsDaemon 0

top -bcSH -n 1 | grep tor | sort -k 9 -r = 26374 debian-+ 20 0 241476 195268 13180 S 42.0 1.2 542:59.10 /usr/bin/tor --defaults-torrc /usr/share/tor/tor-service-defaults-torrc -f /etc/tor/torrc --RunAsDaemon 0

now i use this cmd from ur script

bash killprocess.sh dry top
Process execute in 'dry' mode (no kill).
Process fetched by 'top' command
Process sort by TIME ( 9 )
Check tor process...
There isn't any matched process for tor

killprocess.log:

Process execute in 'kill' mode.
Process fetched by 'top' command
Process sort by %CPU ( 9 )
Check tor process...
There isn't any matched process for tor

perhaps i must use this on the confic

KILLLIST=("tor") >>>>> KILLLIST=(" /usr/bin/tor") ?

killprocess.sh = 755 root

cya
Betaman

from kill-process.

lopadova avatar lopadova commented on July 17, 2024

If you schedule in cron a script with this command:
top -bcSH -n 1 | grep tor | sort -k 9 -r | head -n 1 > /var/log/test.log 2>&1
can you find in the test.log the same resut of shell excuting
26374 debian-+ 20 0 241476 195268 13180 S 18.3 1.2 542:52.02 /usr/bin/tor --defaults-torrc /usr/share/tor/tor-service-defaults-torrc -f /etc/tor/torrc --RunAsDaemon 0
??

if the answere is YES, then change KILLLIST var to:
KILLLIST=("tor")

Best regards,
Lorenzo.

from kill-process.

Betaman2k avatar Betaman2k commented on July 17, 2024

Heya

crontab
test.log
25140 root 20 0 14232 2308 2160 S 0,0 0,0 0:00.00 grep tor

now crazy log with another pidfile :(

one minute later. test.log

26138 root 20 0 14232 2164 2020 S 0,0 0,0 0:00.00 grep tor

i get not this msg
26374 debian-+ 20 0 241476 195268 13180 S 18.3 1.2 542:52.02 /usr/bin/tor --defaults-torrc /usr/share/tor/tor-service-defaults-torrc -f /etc/tor/torrc --RunAsDaemon 0

if i used normal on console cmd
top -bcSH -n 1 | grep tor | sort -k 9 -r | head -n 1
26374 debian-+ 20 0 241476 195268 13180 S 29.1 1.2 548:40.55 /usr/bin/tor --defaults-torrc /usr/share/tor/tor-service-defaults-torrc -f /etc/tor/torrc --RunAsDaemon 0

all ok with normal cmd on console, on crontab not :(

can you find in the test.log the same resut of shell excuting <<<< No, only on shell cmd
cya
Betaman

from kill-process.

lopadova avatar lopadova commented on July 17, 2024

last try...
If you schedule in cron a script with this command (remove "| head -n 1" too):

top -bcSH -n 1 | grep tor | sort -k 9 -r > /var/log/test.log 2>&1

can you find in the test.log tor process (in any position first, last, 10th, ....) or the process list don't write tor process?

Best regards,
Lorenzo.

from kill-process.

lopadova avatar lopadova commented on July 17, 2024

little clarification:
if you don't see "tor" process when try my last tricks:
top -bcSH -n 1 | grep tor | sort -k 9 -r > /var/log/test.log 2>&1

can you schedule in cron another script with this command (remove grep too, so you have the full process list order by CPU):
top -bcSH -n 1 | sort -k 9 -r > /var/log/test.log 2>&1

can you find in the test.log tor process (in any position) or the tor process don't appears?

Best regards,
Lorenzo.

from kill-process.

Betaman2k avatar Betaman2k commented on July 17, 2024

Heya

i get no infos with this crontab top -bcSH -n 1 | grep tor | sort -k 9 -r > /var/log/test.log 2>&1

with this command i get all processes ( crontab )

top -bcSH -n 1 | sort -k 9 -r > /var/log/test.log 2>&1

and yeah i found the process, but all process little cutty

26374 debian-+ 20 0 238168 189176 11836 S 53,0 1,2 562:47.57 /usr/bin/to+

i think grep dont work on crontab

shell cmd

top -bcSH -n 1 | grep tor | sort -k 9 -r = 26374 debian-+ 20 0 238168 189176 11836 R 36.4 1.2 563:46.10 /usr/bin/tor --defaults-torrc /usr/share/tor/tor-service-defaults-torrc -f /etc/tor/torrc --RunAsDaemon 0

with crontab, i get no infos with this pid file from tor
cya
betaman

from kill-process.

lopadova avatar lopadova commented on July 17, 2024

Hi @Betaman2k
in cron log you found this entry:
26374 debian-+ 20 0 238168 189176 11836 S 53,0 1,2 562:47.57 /usr/bin/to+
where process name was "/usr/bin/to+" and not "/usr/bin/tor"
did you mispelled (typo) when copy&paste the log here?
because grep looking for "tor" not "to+"

from kill-process.

Betaman2k avatar Betaman2k commented on July 17, 2024

Heya

yeah i cut nothing, the command ( crontab ) posted all into the test.log ( all cutty )
dunno why

another examples:
1488 mysql 20 0 1844292 197360 6980 S 0,0 1,2 5:27.68 /usr/sbin/m+
2366 www-data 20 0 458396 59176 40952 S 0,0 0,4 0:17.40 /usr/sbin/a+

all cuts

only shell cmd i get the full infos ( top -bcSH -n 1 | sort -k 9 -r )

yeah now process had 100m % load or 99

i check with this shell cmd

top -bcSH -n 1 | grep tor | sort -k 9 -r

26374 debian-+ 20 0 540940 495120 15628 R 99.9 3.0 1338:02 /usr/bin/tor --defaults-torrc /usr/share/tor/tor-service-defaults-torrc -f /etc/tor/torrc --RunAsDaemon 0

u can see he killed nothing
cya
Betaman

from kill-process.

lopadova avatar lopadova commented on July 17, 2024

ook!
we now found the problem:
probabily the cron truncate output command to 80 chars by default.

You can set COLUMNS environment variable to a large value in cron.
Try this for top invocation in you cron:

COLUMNS=1000 top -bcSH -n 1 | sort -k 9 -r > /var/log/test.log 2>&1
or

COLUMNS=1000 
top -bcSH -n 1 | sort -k 9 -r > /var/log/test.log 2>&1

Now in the log, can you see the full process name or truncated output?

Best regards,
Lorenzo.

from kill-process.

Betaman2k avatar Betaman2k commented on July 17, 2024

Heya

strange, now i see all processes correct, only tor is crazy in log file

9943 debian-+ 20 0 122044 76280 15684 S 23,6 0,5 16:45.59 /usr/bin/tor --defaults-torrc /usr/share/tor/tor-service-defaults-torrc -f /etc/tor/torrc --RunAsDaemon 0

another mysql
1488 mysql 20 0 1844292 197360 6980 S 0,0 1,2 5:28.05 /usr/sbin/mysqld

cya
betaman

from kill-process.

lopadova avatar lopadova commented on July 17, 2024

Ok but now if you grep 'tor' or grep ' /usr/bin/tor' in your cron
its all ok?
However, the problem is not the script but environment configuration for your machine.

Best regards,
Lorenzo.

from kill-process.

Betaman2k avatar Betaman2k commented on July 17, 2024

Heya

now i used this on crontab

COLUMNS=1000 top -bcSH -n 1 | grep /usr/bin/tor | sort -k 9 -r > /var/log/test.log 2>&1

log file:
9943 debian-+ 20 0 138316 92632 15684 S 30,1 0,6 46:47.44 /usr/bin/tor --defaults-torrc /usr/share/tor/tor-service-defaults-torrc -f /etc/tor/torrc --RunAsDaemon 0

15342 root 20 0 14232 2312 2160 S 0,0 0,0 0:00.00 grep /usr/bin/tor

i think all good, but now, ur script edit or ?

anotther idea, install tor on ur shell

apt-get install tor

tested himself :)
cya
Betaman

from kill-process.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.