Sponsored Content
Top Forums Shell Programming and Scripting Find the Pid and Kill the Process after a Few Minutes Post 302886663 by balajesuri on Monday 3rd of February 2014 05:43:32 AM
Old 02-03-2014
-o pid is a format specifier for the ps command that prints only the PID's of the processes specfied by the -c switch (in this case "myscript.sh"). But this will print the default column header name "PID" and then list all the pid's below this header. To have a different header name, you could simply say -o pid="MyScriptPIDs".

Here, we are not supplying any header name in -o pid= , which means no header will be printed and so that you could use the output in kill command.
This User Gave Thanks to balajesuri For This Post:
 

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

How to kill a process and its childs given pid and userid

I need to write a shell script which would take 2 arguments pid , userid. Then it should kill all the child process under it. If a child process is not killed then it should wait for 1 minute and should kill. can anybody give me the idea to write it? (0 Replies)
Discussion started by: nani_g
0 Replies

3. 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

4. Solaris

how to find PID of a runnign process ?

Hi Friends, How can we find the process ID of a running process using the process name. In AIX I used to use the command "ps -ef | grep <process name>", it used to give me the owner of that process, Process ID and the threads running and the name of the process in the end. However in... (2 Replies)
Discussion started by: sahilsardana
2 Replies

5. UNIX for Dummies Questions & Answers

How to Kill process with dynamic PID?

Hello, I have problem with killing red5 process running on linux server. As this process is continuously changing its PID so it can't be killed with "kill -9 PID" command. First I used following command to list RED5 process ps aux | grep red5 which showed me root 5832 0.0 0.0 4820 756pts/0... (1 Reply)
Discussion started by: ninadgac
1 Replies

6. Shell Programming and Scripting

How to Kill process with dynamic PID?

Hello, I have problem with killing red5 process running on linux server. As this process is continuously changing its PID so it can't be killed with "kill -9 PID" command. First I used following command to list RED5 process ps aux | grep red5 which showed me root 5832 0.0 0.0 4820 756pts/0... (4 Replies)
Discussion started by: ninadgac
4 Replies

7. Red Hat

How to Force KILL State -D Process/PID?

Hi Expert, I am not able to kill certain user process as root. I have tried using: pkill -u uname skill KILL -u uname kill -9 PID *** I have not using killall yet, since this server has more than 100 users online atm. PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND... (1 Reply)
Discussion started by: regmaster
1 Replies

8. Shell Programming and Scripting

Find PID for a process

I want to kill a process run by a user of another group. How do I do that..? (3 Replies)
Discussion started by: Haimanti
3 Replies

9. Shell Programming and Scripting

Kill nohup process with changing PID

Hi there! I have a tricky problem concerning a nohup process: I started a python2.7 script which loops over a function. At the end it restarts the function. Due to a mistake I'm now having a never ending nohup process that I have to kill. I started the program execution with: >>nohup... (4 Replies)
Discussion started by: Lydia
4 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
timer(3erl)						     Erlang Module Definition						       timer(3erl)

NAME
timer - Timer Functions DESCRIPTION
This module provides useful functions related to time. Unless otherwise stated, time is always measured in milliseconds . All timer func- tions return immediately, regardless of work carried out by another process. Successful evaluations of the timer functions yield return values containing a timer reference, denoted TRef below. By using cancel/1 , the returned reference can be used to cancel any requested action. A TRef is an Erlang term, the contents of which must not be altered. The timeouts are not exact, but should be at least as long as requested. EXPORTS
start() -> ok Starts the timer server. Normally, the server does not need to be started explicitly. It is started dynamically if it is needed. This is useful during development, but in a target system the server should be started explicitly. Use configuration parameters for kernel for this. apply_after(Time, Module, Function, Arguments) -> {ok, Tref} | {error, Reason} Types Time = integer() in Milliseconds Module = Function = atom() Arguments = [term()] Evaluates apply(M, F, A) after Time amount of time has elapsed. Returns {ok, TRef} , or {error, Reason} . send_after(Time, Pid, Message) -> {ok, TRef} | {error,Reason} send_after(Time, Message) -> {ok, TRef} | {error,Reason} Types Time = integer() in Milliseconds Pid = pid() | atom() Message = term() Result = {ok, TRef} | {error, Reason} send_after/3 : Evaluates Pid ! Message after Time amount of time has elapsed. ( Pid can also be an atom of a registered name.) Returns {ok, TRef} , or {error, Reason} . send_after/2 : Same as send_after(Time, self(), Message) . exit_after(Time, Pid, Reason1) -> {ok, TRef} | {error,Reason2} exit_after(Time, Reason1) -> {ok, TRef} | {error,Reason2} kill_after(Time, Pid)-> {ok, TRef} | {error,Reason2} kill_after(Time) -> {ok, TRef} | {error,Reason2} Types Time = integer() in milliseconds Pid = pid() | atom() Reason1 = Reason2 = term() exit_after/3 : Send an exit signal with reason Reason1 to Pid Pid . Returns {ok, TRef} , or {error, Reason2} . exit_after/2 : Same as exit_after(Time, self(), Reason1) . kill_after/2 : Same as exit_after(Time, Pid, kill) . kill_after/1 : Same as exit_after(Time, self(), kill) . apply_interval(Time, Module, Function, Arguments) -> {ok, TRef} | {error, Reason} Types Time = integer() in milliseconds Module = Function = atom() Arguments = [term()] Evaluates apply(Module, Function, Arguments) repeatedly at intervals of Time . Returns {ok, TRef} , or {error, Reason} . send_interval(Time, Pid, Message) -> {ok, TRef} | {error, Reason} send_interval(Time, Message) -> {ok, TRef} | {error, Reason} Types Time = integer() in milliseconds Pid = pid() | atom() Message = term() Reason = term() send_interval/3 : Evaluates Pid ! Message repeatedly after Time amount of time has elapsed. ( Pid can also be an atom of a registered name.) Returns {ok, TRef} or {error, Reason} . send_interval/2 : Same as send_interval(Time, self(), Message) . cancel(TRef) -> {ok, cancel} | {error, Reason} Cancels a previously requested timeout. TRef is a unique timer reference returned by the timer function in question. Returns {ok, cancel} , or {error, Reason} when TRef is not a timer reference. sleep(Time) -> ok Types Time = integer() in milliseconds or the atom infinity Suspends the process calling this function for Time amount of milliseconds and then returns ok , or suspend the process forever if Time is the atom infinity . Naturally, this function does not return immediately. tc(Module, Function, Arguments) -> {Time, Value} tc(Fun, Arguments) -> {Time, Value} Types Module = Function = atom() Fun = fun() Arguments = [term()] Time = integer() in microseconds Value = term() tc/3 : Evaluates apply(Module, Function, Arguments) and measures the elapsed real time as reported by now/0 . Returns {Time, Value} , where Time is the elapsed real time in microseconds , and Value is what is returned from the apply. tc/2 : Evaluates apply(Fun, Arguments) . Otherwise works like tc/3 . now_diff(T2, T1) -> Tdiff Types T1 = T2 = {MegaSecs, Secs, MicroSecs} Tdiff = MegaSecs = Secs = MicroSecs = integer() Calculates the time difference Tdiff = T2 - T1 in microseconds , where T1 and T2 probably are timestamp tuples returned from erlang:now/0 . seconds(Seconds) -> Milliseconds Returns the number of milliseconds in Seconds . minutes(Minutes) -> Milliseconds Return the number of milliseconds in Minutes . hours(Hours) -> Milliseconds Returns the number of milliseconds in Hours . hms(Hours, Minutes, Seconds) -> Milliseconds Returns the number of milliseconds in Hours + Minutes + Seconds . EXAMPLES
This example illustrates how to print out "Hello World!" in 5 seconds: 1> timer:apply_after(5000, io, format, ["~nHello World!~n", []]). {ok,TRef} Hello World! The following coding example illustrates a process which performs a certain action and if this action is not completed within a certain limit, then the process is killed. Pid = spawn(mod, fun, [foo, bar]), %% If pid is not finished in 10 seconds, kill him {ok, R} = timer:kill_after(timer:seconds(10), Pid), ... %% We change our mind... timer:cancel(R), ... WARNING
A timer can always be removed by calling cancel/1 . An interval timer, i.e. a timer created by evaluating any of the functions apply_interval/4 , send_interval/3 , and send_interval/2 , is linked to the process towards which the timer performs its task. A one-shot timer, i.e. a timer created by evaluating any of the functions apply_after/4 , send_after/3 , send_after/2 , exit_after/3 , exit_after/2 , kill_after/2 , and kill_after/1 is not linked to any process. Hence, such a timer is removed only when it reaches its time- out, or if it is explicitly removed by a call to cancel/1 . Ericsson AB stdlib 1.17.3 timer(3erl)
All times are GMT -4. The time now is 12:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy