How to interrupt running application?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to interrupt running application?
# 1  
Old 12-14-2012
How to interrupt running application?

Hello

i have problem passing ctrl+C into shell script

this script will run application and return value but never ends and stay running.

i tried trap and not working at all


the command should look like this :

Code:
sarm pcsp  -s CHG_M_P1

i want something to stop this command after output !

can you help
# 2  
Old 12-14-2012
You mean to say you want to kill it after the output within the script. or from the console.


You can try to find the
Code:
PID

of this process and use
Code:
kill

command after you get your output.
# 3  
Old 12-14-2012
Quote:
Originally Posted by Vikram_Tanwar12
You mean to say you want to kill it after the output within the script. or from the console.


You can try to find the
Code:
PID

of this process and use
Code:
kill

command after you get your output.
in shell scripting another command/line will not run until end of the first command
so when put this line
Code:
sarm pcsp  -s CHG_M_P1

it will never ends,
kill, trap , signulhup nothing will works because this command line not end
# 4  
Old 12-14-2012
do this exactly from your command line:

Code:
ps -ef | grep 'sarm pcsp'

This will give you something that looks like this
Code:
  mogabr 25675  9253   0   Dec 14 ?           0:00 sarm pcsp  -s CHG_M_P1
  mogabr   1234  7765  0   Dec 14 ?            0:00 grep sarm pcsp

See the red number? That is the pid of the process. The actual number you see will be different. So get that number:
Code:
kill  [number you found goes here]

That will stop the running application. If does not (because you have a trap stement in the code) then try:
Code:
kill -9 [number you found goes here]

kill -9 is NOT a great idea, it may leave things like files in an undefined state.
# 5  
Old 12-14-2012
You can also use
Code:
kill -9 pid

# 6  
Old 12-14-2012
Quote:
Originally Posted by Vikram_Tanwar12
You can also use
Code:
kill -9 pid


well

i think i cant explain in details

my question is
how to pass CTRL+C to run automatic in shell scripting as batch mode

---------- Post updated at 07:46 AM ---------- Previous update was at 07:38 AM ----------

Quote:
Originally Posted by jim mcnamara
do this exactly from your command line:

Code:
ps -ef | grep 'sarm pcsp'

This will give you something that looks like this
Code:
  mogabr 25675  9253   0   Dec 14 ?           0:00 sarm pcsp  -s CHG_M_P1
  mogabr   1234  7765  0   Dec 14 ?            0:00 grep sarm pcsp

See the red number? That is the pid of the process. The actual number you see will be different. So get that number:
Code:
kill  [number you found goes here]

That will stop the running application. If does not (because you have a trap stement in the code) then try:
Code:
kill -9 [number you found goes here]

kill -9 is NOT a great idea, it may leave things like files in an undefined state.
yes this works good if manual on unix

how to do that in shell scriptting as following

1-run command XXX which will not end
2-kill command XXX


u know that shell scripting is a procedural language means every line should be executed and ended so next line can run
in this case i can never go to kill command because the previous line XXX command never ends
# 7  
Old 12-14-2012
Yes I do understand scripting....

What you are asking does not make sense.

Assume you are a shell script, executing. How can you know if you are stuck?
You can only guess. Code for how long you are willing to wait then force an exit.
3600 = number of seconds in one hour
Code:
pid=$$
# kill the parent after 3600 seconds
sleep 3600 && kill $pid 2>/dev/null &
child_pid=$!
# [command that runs too long goes here]
sarm pcsp -s 
# if  sarm completed in less than 3600 seconds you get here
kill $child_pid   # stop the child from killing you.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Bash pauses while application running

I want a really easy thing to happen, I want the bash to open a picture with QuickPictureViewer (qpv) and then some seconds or after a if function with some specific value that this process is terminated. The problem is, that the bash opens the picture and the script doesn´t go on (because the... (2 Replies)
Discussion started by: SasuGamer
2 Replies

2. UNIX for Beginners Questions & Answers

Application server is running or not

Hi All, i am trying to find whether nginx is installed or not as well process is running or not on my centos server. For that i am searching for the nginx configuration file nginx.conf based on that i am printing the ouput. Below script i am using. var=$(find / -name "nginx.conf" !... (1 Reply)
Discussion started by: balu1234
1 Replies

3. UNIX for Advanced & Expert Users

Is there any shell command to show which interrupt handler handle which interrupt number?

Hi, all: Is there any shell command to show which interrupt handler handle which interrupt number in the system? li,kunlun (5 Replies)
Discussion started by: liklstar
5 Replies

4. UNIX for Advanced & Expert Users

Interrupt storm detected on "irq 20" throttling interrupt source

I receive the following warning messages on a very new machine which has FreeBSD 8.1 x64 installed on it: Interrupt storm detected on "irq 20" throttling interrupt source It is unclear what this means and what its origins are (motherboard? CPU? RAM?). I can start the desktop and the message is... (4 Replies)
Discussion started by: figaro
4 Replies

5. UNIX for Dummies Questions & Answers

How to start application and keep script running

What I'm looking for is best explained with a little example. #!/bin/bash gedit echo "I need this message to appear while gedit is still running, but it appears only then when I close gedit." Of course most of the times you want the script to wait, but in this case I want to start a new... (5 Replies)
Discussion started by: MrZehl
5 Replies

6. Shell Programming and Scripting

Know when a particular application is running

Is it possible in unix to write a script that could determine when a particular application is running or not ? (3 Replies)
Discussion started by: zapper222
3 Replies

7. Solaris

How to find an application running on multithread?

Dear Friends, We have one T5240 server with 128vcpus in our lab.Performance of the server is very poor. Application uses only 2% of processor..I heard that single thread application performs slowly in coolthread.How can we find whether the application running on multithread or single thread? If... (7 Replies)
Discussion started by: nicktrix
7 Replies

8. Shell Programming and Scripting

command to know the application running of the port

Hi, is there any command to findout that which application is using the particular port. or whether any port is occupied with the specfic process id ? (4 Replies)
Discussion started by: mail2sant
4 Replies

9. Shell Programming and Scripting

Query on sending inputs to a running application

Hi I need a help for below : I am running an application XXXX , and when it starts i am passing a file name called "connect.spb" and after the application connects to the server i am sending filename "accept.spb" as a parameter. DL385:$ ./XXXX This is XXXX (Reproducer by Order or RelaY) ... (1 Reply)
Discussion started by: srkelect
1 Replies

10. UNIX for Dummies Questions & Answers

Script to Test Application Server is running

Hi, I'm a complete novice at Unix and need to create a script that does the following... checks to see if an application server is running. If the app is running then print 'Available' Else print 'Unavaliable' exit from scriopt I have no idea where to start. I'd be very grateful... (0 Replies)
Discussion started by: duglover
0 Replies
Login or Register to Ask a Question