Sponsored Content
Top Forums Shell Programming and Scripting Kill a Script based on the pid and sleep Post 302358937 by pludi on Monday 5th of October 2009 08:40:56 AM
Old 10-05-2009
Yes, there is:
Code:
#!/usr/bin/ksh

trap "exit 1" 10

( sleep 60 && kill -10 $$ ) &
WATCH=$!
SLEEP=${1:-60}

sleep $SLEEP

kill -TERM $WATCH

Exemplary output:
Code:
$ ./test.sh 5; echo $?
0
$ ./test.sh 61; echo $?
1

Note that I'm using SIGUSR1 instead of SIGKILL for the timeout, to keep the latter free for serious problems.
 

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
SCRIPTMGR(1)															      SCRIPTMGR(1)

NAME
scriptmgr - utility for controlling other skytools scripts. SYNOPSIS
scriptmgr.py [switches] config.ini <command> [-a | job_name ... ] DESCRIPTION
scriptmgr is used to manage several scripts together. It discovers potential jobs based on config file glob expression. From config file it gets both job_name and service type (that is the main section name eg [cube_dispatcher]). For each service type there is subsection in the config how to handle it. Unknown services are ignored. COMMANDS
status scriptmgr config.ini status Show status for all known jobs. start scriptmgr config.ini start -a scriptmgr config.ini start job_name1 job_name2 ... launch script(s) that are not running. stop scriptmgr config.ini stop -a scriptmgr config.ini stop job_name1 job_name2 ... stop script(s) that are running. restart scriptmgr config.ini restart -a scriptmgr config.ini restart job_name1 job_name2 ... restart scripts. reload scriptmgr config.ini reload -a scriptmgr config.ini reload job_name1 job_name2 ... Send SIGHUP to scripts that are running. CONFIG
Common configuration parameters job_name Name for particulat job the script does. Script will log under this name to logdb/logserver. The name is also used as default for PgQ consumer name. It should be unique. pidfile Location for pid file. If not given, script is disallowed to daemonize. logfile Location for log file. loop_delay If continuisly running process, how long to sleep after each work loop, in seconds. Default: 1. connection_lifetime Close and reconnect older database connections. log_count Number of log files to keep. Default: 3 log_size Max size for one log file. File is rotated if max size is reached. Default: 10485760 (10M) use_skylog If set, search for [./skylog.ini, ~/.skylog.ini, /etc/skylog.ini]. If found then the file is used as config file for Pythons logging module. It allows setting up fully customizable logging setup. scriptmgr parameters config_list List of glob patters for finding config files. Example: config_list = ~/dbscripts/conf/*.ini, ~/random/conf/*.ini Service section parameters cwd Working directory for script. args Arguments to give to script, in addition to -d. script Path to script. Unless script is in PATH, full path should be given. disabled If this service should be ignored. Example config file [scriptmgr] job_name = scriptmgr_livesrv logfile = ~/log/%(job_name)s.log pidfile = ~/pid/%(job_name)s.pid config_list = ~/scripts/conf/*.ini # defaults for all service sections [DEFAULT] cwd = ~/scripts [table_dispatcher] script = table_dispatcher.py args = -v [cube_dispatcher] script = python2.4 cube_dispatcher.py disabled = 1 [pgqadm] script = ~/scripts/pgqadm.py args = ticker COMMAND LINE SWITCHES
Following switches are common to all skytools.DBScript-based Python programs. -h, --help show help message and exit -q, --quiet make program silent -v, --verbose make program more verbose -d, --daemon make program go background Following switches are used to control already running process. The pidfile is read from config then signal is sent to process id specified there. -r, --reload reload config (send SIGHUP) -s, --stop stop program safely (send SIGINT) -k, --kill kill program immidiately (send SIGTERM) Options specific to scriptmgr: -a, --all Operate on all non-disabled scripts. 03/13/2012 SCRIPTMGR(1)
All times are GMT -4. The time now is 04:31 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy