how to kill process from file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to kill process from file
# 8  
Old 09-18-2005
Quote:
Originally Posted by reborg
Yes, if you explained a bit more clearly where you are having problems.
hi
i don't understand ay of the syntax , i can't see how you seperated the hour from the process (which apperance in the same line of the file )
can you please explain
my loop goes like this :
cat bbb | while read line
do
then what ???
done
note the file looks like this
0:11 15639
0:30 5555
thank you very much .
# 9  
Old 09-18-2005
Quote:
Originally Posted by reborg
IFS='[ :<tab>]'
Set the internal field seperator to space, : or tab <tab> is used here to denote an actual tab character.

Quote:
while read a b pid
Ok, lets break down a line in your file

0:30 54545 According to what I set IFS to this has 3 fields, I have decided to call them a,b and pid { a=0, b=30, pid=54545 }
Quote:
[[ $a$b -gt 30 ]] && kill $pid
is the concatenation of $a and $b > 30 ? if so kill the process identified by pid

in this example

[[ 030 -gt 30 ]] && kill $pid

evaluates to false so the process does not get killed.

Quote:
done < bbb
Take the input from the file bbb, this the same as your "cat bbb | while" except without the UUOC.
# 10  
Old 09-20-2005
Quote:
Originally Posted by reborg
Set the internal field seperator to space, : or tab <tab> is used here to denote an actual tab character.



Ok, lets break down a line in your file

0:30 54545 According to what I set IFS to this has 3 fields, I have decided to call them a,b and pid { a=0, b=30, pid=54545 }

is the concatenation of $a and $b > 30 ? if so kill the process identified by pid

in this example

[[ 030 -gt 30 ]] && kill $pid

evaluates to false so the process does not get killed.


Take the input from the file bbb, this the same as your "cat bbb | while" except without the UUOC.
hi my unix o.s doen't know the IFS and the -gt command
so what i did is
cat bbb | while read line
do
bsd = echo $line | cut -c 1-4
bsd1= echo $line | cut -c 6-11
done
now i don't know how to ask about the bsd variable if it's greater then
30minutes and kill the process
# 11  
Old 09-20-2005
The script given by reborg will run in ksh without any problems. But assuming that you have an old box and no ksh, you can use this:

Code:
#!/bin/sh
#set -x                 # unhash to debug

while read time procid; do
hrs=`echo $time|cut -d':' -f1`
min=`echo $time|cut -d':' -f2`
if [ "$min" -gt 30 ]; then
        kill $procid
fi
done< bbb                #bbb is the filename as per your question

This assumes that the 'hr:min' field will never have a number such as 1:20 which means that while 20 is less than the 30 min that you want, the process has been running for over an hour.

Last edited by blowtorch; 09-20-2005 at 04:32 AM.. Reason: change "echo $procid" to "kill $procid"
# 12  
Old 09-20-2005
Quote:
Originally Posted by blowtorch
The script given by reborg will run in ksh without any problems. But assuming that you have an old box and no ksh, you can use this:

Code:
#!/bin/sh
#set -x                 # unhash to debug

while read time procid; do
hrs=`echo $time|cut -d':' -f1`
min=`echo $time|cut -d':' -f2`
if [ "$min" -gt 30 ]; then
        kill $procid
fi
done< bbb                #bbb is the filename as per your question

This assumes that the 'hr:min' field will never have a number such as 1:20 which means that while 20 is less than the 30 min that you want, the process has been running for over an hour.
i did reborgs' sugesstion i wrote at the beggining of the script
#!/usr/bin/ksh
i'm running my script like this
sh cs-sonia (name of the script)
and it's writing to me
UX:sh (cs-sonia): ERROR: 001 21489: not found
for each process what seems to be the problem???
please help me
another question why is it kill $pid and not kill -9 $pid
thanks a lot
# 13  
Old 09-20-2005
use ksh, not sh to run the script. You are overriding the #!/usr/bin/ksh by running the script as sh cs-sonia.

kill, not kill -9 to send SIGTERM, not SIGKILL to the proccess. SIGKILL does not allow the process to "clean up" as it exits.
# 14  
Old 09-21-2005
Quote:
Originally Posted by reborg
use ksh, not sh to run the script. You are overriding the #!/usr/bin/ksh by running the script as sh cs-sonia.

kill, not kill -9 to send SIGTERM, not SIGKILL to the proccess. SIGKILL does not allow the process to "clean up" as it exits.
hi reborg
thanks a lot reborg it's work
but i want to remark something
when i did just kill it did not kill the process just kill -9
i still don't get why did you think that just kill
second thing
i want that this script will run automatic every 30 minutes how can i do that i understand that the command is sleep
but i do'nt know how to write it
should i write it from the working directory where the script run ?
thanks for quick response
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to report file size, pid and also kill the process

Hi All, Looking for a quick LINUX shell script which can continuously monitors the flle size, report the process which is creating a file greater than certain limit and also kill that process. Can someone please help me on this? (4 Replies)
Discussion started by: vasavimacherla
4 Replies

2. Shell Programming and Scripting

How to kill the process when the file is locked?

I was trying to read the file to create a table in SAS and I got error as follows while I read. Resource is write-locked by another user. File =/usr/sas/sas_config/Lev1/SASApp/StoredProcessServ​er/Logs/SASApp_STPServer_2015-09-29_tmp_18208.log. System Error Code = 0. ERROR: File is in... (10 Replies)
Discussion started by: Ram Kumar_BE
10 Replies

3. Shell Programming and Scripting

Soft kill a process to redirect the last kbytes output to a file

Hey guys, I have a python script that I call with this line: python mypythonscript.py >> results.csv &The problem is that the redirection from the stdout to the file results.csv only writes 4096 kbyte blocks. So if i kill this process with kill the last kbytes that the script produce will... (6 Replies)
Discussion started by: Mastaer
6 Replies

4. Shell Programming and Scripting

Kill an specific process ID using the KILL and GREP commands

Good afternoon I need to KILL a process in a single command sentence, for example: kill -9 `ps -aef | grep 'CAL255.4ge' | grep -v grep | awk '{print $2}'` That sentence Kills the process ID corresponding to the program CAL255.4ge. However it is possible that the same program... (6 Replies)
Discussion started by: enriquegm82
6 Replies

5. Shell Programming and Scripting

kill process from a file or directly with top

i have edited a script to kill an exact mysql process is causing the high load on the server, my problem is, kill dont kill it! script: #!/bin/sh top -n 1 -u mysql | grep mysqld | awk '{print $1}' > pid proc='cat pid' kill -9 $proc or i try with kill -9 `top -n 1 -u mysql | grep mysqld... (8 Replies)
Discussion started by: chandro
8 Replies

6. Linux

Kill a process without using kill command

I want to Kill a process without using kill command as i don't have privileges to kill the process. I know the pid and i am using Linux 2.6.9 OS. (6 Replies)
Discussion started by: sudhamacs
6 Replies

7. Shell Programming and Scripting

Kill a process without using kill command

Sorry, posted the question in other forum. (0 Replies)
Discussion started by: sudhamacs
0 Replies

8. Programming

kill(0,-9) don't kill the process

Hi all i have simple c program , when i wish to kill the app im using kill(0,-9) , but it seams this command don't do any thing and the program. just ignore it . what im doing wrong here ? im using HP-UX ia64 Thanks (9 Replies)
Discussion started by: umen
9 Replies

9. UNIX for Advanced & Expert Users

When kill doesnt work, how to kill a process ?

Hi All, I am unable to kill a process using kill command. I am using HP-UX system. I have tried with kill -9 and i have root privilages. How can i terminate this daemon ? ? ? Regards, Vijay Hegde (3 Replies)
Discussion started by: VijayHegde
3 Replies

10. Post Here to Contact Site Administrators and Moderators

how to kill process from file

hello i want to write a script in unix which read file that contains : hour and process_id like this file bbb: 0:30 6678 1:40 8789 and for every line he check if the hour greater then 30 minutes he kill the process_id the script looks like this cat bbb | while read line do ... (1 Reply)
Discussion started by: naamas03
1 Replies
Login or Register to Ask a Question