Find a process ID,kill it and restart agent


 
Thread Tools Search this Thread
Operating Systems Linux Find a process ID,kill it and restart agent
# 8  
Old 08-28-2015
Replace the last pipe with a semicolon, and check the chars at the end of the line.
# 9  
Old 08-28-2015
Sorry, but the idea of using "ps" inside (any form of) a script to manipulate processes is flawed from the start.

Processes are allowed to lie about their credentials, except to their parents. For automatically (a script is a sort of automaton) parsing ps output scripts are simply not smart enough. ps is designed for interactive use because systems administrators are supposed to be smarter than scripts.

Having said this: i do not know this hawkagent program, but it has to be started somewhere. This "somewhere" is most probably /etc/inittab. Start it there with the clause respawn and the system will restart it for you every time it stops. The system (to be precise: its init process) will even be safe in doing so because init will be the trueparent of the process.

Everything else is risky at best and terminal to the system at worst.

I hope this helps.

bakunin

PS: if your system has no /etc/inittab get runit or daemontools.
# 10  
Old 08-28-2015
is there a way to come out automatically from nohup? Following code remains in a hung state and control is never returned.

Code:
nohup ./hawkagent_BWQA &

# 11  
Old 08-28-2015
"Control" is not meant to return. By sending the process to background with & you chop it off normal terminal stdin. And, with nohup on top, you remove the HUP signal path from its parent (your interactive process), and the init process becomes its parent.
You'll have to build in extra code for interaction with the outer world, e.g. via FIFOs.
# 12  
Old 09-02-2015
I think in some|most cases neither the & nor the nohup chop the shell's input and output.
Therefore I recommend to explicitly redirect the std handles
Code:
nohup ./hawkagent_BWQA </dev/null >/dev/null 2>&1 &

# 13  
Old 09-02-2015
The phrasing may have been a bit unlucky. If a process sent to background tries to read from the terminal, although still having stdin pointing to the terminal, it assumes a stopped state, so it doesn't interfere with the interactive shell. By sending a process to bg, you intentionally cede interactive control.
You can get back "control" by putting it into foreground with the fg command.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find the Pid and Kill the Process after a Few Minutes

hi guys i had written a shell script Display Information of all the File Systems i want to find the pid and kill the process after few minutes.how can i obtain the pid and kill it??? sample.sh df -a >> /tmp/size.log and my cron to execute every minute every hour every day * *... (5 Replies)
Discussion started by: azherkn3
5 Replies

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

3. Shell Programming and Scripting

shell script to find a process by name and kill it

hi, Am a newbie to unix and wasnt able to write script to my requirement. I need a shell script, which should find a process by name and kill it. For eg: let the process name be "abc". I have different processes running by this name(abc), so should kill them all. Condition would be: if... (7 Replies)
Discussion started by: fop4658
7 Replies

4. Shell Programming and Scripting

Shell Script to Kill Process(number of process) Unix/Solaris

Hi Experts, we do have a shell script for Unix Solaris, which will kill all the process manullay, it used to work in my previous env, but now it is throwing this error.. could some one please help me to resolve it This is how we execute the script (and this is the requirement) ... (2 Replies)
Discussion started by: jonnyvic
2 Replies

5. Shell Programming and Scripting

Unix Script to find and kill a process with high memory utilization

Hi Unix Gurus i am somewhat new to unix scripting so need your help to create a script as below. # This script would find the process consuming memory beyond a certain #limit. if the meemory consumption is more than 100% for a period of 1 # minute for the specific process. the script would... (0 Replies)
Discussion started by: robinforlinux
0 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. Shell Programming and Scripting

how to start a process and make it sleep for 5 mins and then kill that process

how to start a process and make it sleep for 5 mins and then kill that process (6 Replies)
Discussion started by: shrao
6 Replies

10. 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
Login or Register to Ask a Question