Sponsored Content
Top Forums Shell Programming and Scripting Kill a Script based on the pid and sleep Post 302358895 by infernalhell on Monday 5th of October 2009 07:02:01 AM
Old 10-05-2009
Kill a Script based on the pid and sleep

I would want to run a code for 1 min and if it doesnt succeed in 1 min..I would want to exit it..I am using the following code...But the script is not going into my code part.It is waiting for 60 secs and then getting killed.
The code which is in the while loop actually takes less than 60 secs...
Could someone look into the below code

Code:
echo $$ > myprog.lck
echo sleep 60 > mytmp.sh
echo kill -9 \`cat myprog.lck\` >> mytmp.sh
sh mytmp.sh & 

while true;  

do 

  code

done 
exit 1


Last edited by pludi; 10-05-2009 at 08:18 AM.. Reason: code tags please...
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Script to kill all child process for a given PID

Is there any build in command in unix to kill all the child process for a given process ID ? If any one has script or command, please let me know. Thanks Sanjay (4 Replies)
Discussion started by: sanjay92
4 Replies

2. Shell Programming and Scripting

pass pid to kill using script

Hi there, i wonder if anyone can help is there any way that i can write a script that will kill all current ftp processes, for example if ps -ef | grep ftp produces 3 active proceses, then I would like to somehow extract the PID for each one and pass that to kill -9 has anybody done this... (2 Replies)
Discussion started by: hcclnoodles
2 Replies

3. Shell Programming and Scripting

KILL PID, intern should kill another PID.

Hi All, In my project i have two process runs in the back end. Once i start my project, and execute the command ps, i get below output: PID TTY TIME CMD 9086 pts/1 0:00 ksh 9241 pts/1 0:02 java 9240 pts/1 0:00 shell_script_bg java with 9241 PID is the main... (4 Replies)
Discussion started by: rkrgarlapati
4 Replies

4. UNIX for Advanced & Expert Users

KILL without PID

Hellow Experts i have one problem. i run one script in backgroun. and i want to kill that script with only script name..... so what's the solution.. for your info my script name is "testscript" n it contains "sleep 100" thanks.... (16 Replies)
Discussion started by: luckypower
16 Replies

5. Shell Programming and Scripting

grab PID of a process and kill it in a script

#!/bin/sh who echo "\r" echo Enter the terminal ID of the user in use: echo "\r" read TERM_ID echo "\r" ps -t $TERM_ID | grep sh echo "\r" echo Enter the process number to end: echo "\r" read PID echo "\r" kill -9 $PID What this code does is ultimately grab the PID of a users sh... (6 Replies)
Discussion started by: psytropic
6 Replies

6. Shell Programming and Scripting

Kill a PID using script

Hi, I wrote a script to kill a process id. I am able to kill the PID only if I enter the root password in the middle of the execution because I did not run as root i.e after i run the script from the terminal, instead of killing directly, it is killing only after entering the pass when it... (12 Replies)
Discussion started by: rajkumarme_1
12 Replies

7. Shell Programming and Scripting

Unix Script -- Suggestions to list and kill PID's sequentially

Hi, I'm trying to write a script where i'm trying to grep the PID and the associated file and list them. Then execute the KILL command sequentially on the listed PID's for ".tra" files ==================================================== ps -aux | grep mine adm 27739 0.2 0.8 1131588... (12 Replies)
Discussion started by: murali1687
12 Replies

8. Shell Programming and Scripting

script to kill a pid giving error

Hi, I simply want to kill a running process using a script that read pid from a file and tries to kill it .Getting error as shown below code.. cat $HOME/BackupScript.ksh.run | head -1 | while read pid do ps -p $pid > /dev/null 2>&1 if ; then kill -9 $pid else echo "no running $pid... (5 Replies)
Discussion started by: dhirajdsharma
5 Replies

9. AIX

Kill pid

I created a program to kill long running pid processes. I am getting the following error message: -f command cannot be found. I also want to count the number of pids that are killed and append the results to a text file. I am new to shell script programming. 1.The first part of code... (10 Replies)
Discussion started by: dellanicholson
10 Replies

10. 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
wait(1) 						      General Commands Manual							   wait(1)

NAME
wait - Awaits process completion SYNOPSIS
wait [pid] Note The C shell has a built-in version of the wait command. If you are using the C shell, and want to guarantee that you are using the command described here, you must specify the full path /usr/bin/wait. See the csh(1) reference page for a description of the built-in command. STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: wait: XCU5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. OPTIONS
None OPERANDS
One of the following: The unsigned decimal integer process ID of a command, for which the utility is to wait for the termination. A job control job ID that identifies a background process group to be waited for. The job control job ID notation is applicable only for invoca- tions of wait in the current shell execution environment. The exit status of wait is determined by the last command in the pipeline. DESCRIPTION
When an asynchronous list is started by the shell, the process ID of the last command in each element of the asynchronous list becomes known in the current shell execution environment. If the wait utility is invoked with no operands, it waits until all process IDs known to the invoking shell have terminated and exits with a zero exit status. If one or more pid operands are specified that represent known process IDs, the wait utility waits until all of them have terminated. If one or more pid operands are specified that represent unknown process IDs, wait treats them as if they were known process IDs that exited with exit status 127. The exit status returned by the wait utility is the exit status of the process requested by the last pid operand. The known process IDs are applicable only for invocations of wait in the current shell execution environment. RESTRICTIONS
If wait is called in a subshell or separate utility execution environment, such as one of the following, it returns immediately because there are no known process IDs to wait for in those environments: (wait) nohup wait ... find . -exec wait ... ; If the exit status of wait is greater than 128, there is no way for the application to know if the waited-for process exited with that value or was killed by a signal. Since most utilities exit with small values, there is seldom any ambiguity. EXIT STATUS
If one or more parameters were specified, all of them have terminated or were not known by the invoking shell, and the status of the last parameter specified is known, then the exit status of wait is the exit status information of the command indicated by the last parameter specified. If the process terminated abnormally due to the receipt of a signal, the exit status is greater than 128 and is distinct from the exit status generated by other signals. (See the kill -l option.) Otherwise, the wait utility exits with one of the following values: The wait utility was invoked with no operands and all process IDs known by the invoking shell have terminated. The wait utility detected an error. The command identified by the last pid operand specified is unknown. EXAMPLES
Although the exact value used when a process is terminated by a signal is unspecified, if it is known that a signal terminated a process, a script can still reliably figure out which signal using kill as shown by the following script: sleep 1000& pid=$! kill -kill $pid wait $pid echo $pid was terminated by a SIG$(kill -l $?) signal. If either sequence of commands shown on the first two lines is run in less than 31 seconds either of the commands shown on lines 3 and 4 will return the exit sta- tus of the second sleep in the pipeline: sleep 257 | sleep 31 & jobs -l %% wait <pid of sleep 31> wait %% ENVIRONMENT VARIABLES
The following environment variables affect the execution of wait: Provides a default value for the internationalization variables that are unset or null. If LANG is unset or null, the corresponding value from the default locale is used. If any of the internationalization vari- ables contain an invalid setting, the utility behaves as if none of the variables had been defined. If set to a non-empty string value, overrides the values of all the other internationalization variables. Determines the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multibyte characters in arguments). Determines the locale used to affect the format and contents of diagnostic messages written to standard error. Determines the location of message catalogues for the processing of LC_MESSAGES. SEE ALSO
Commands: bg(1), csh(1), fg(1), jobs(1), kill(1), ksh(1), sh(1) Functions: wait(2) Standards: standards(5) wait(1)
All times are GMT -4. The time now is 10:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy