Sponsored Content
Top Forums Shell Programming and Scripting Trying to kill a program via help command. Post 302187725 by TiznaraN on Monday 21st of April 2008 11:41:58 PM
Old 04-22-2008
Error Trying to kill a program via help command.

Hi all, I have a program and I'm trying to kill it. I'm probably going the longest way around of doing it but now that I've tried to get this to work for a few hours I'd appreciate some help Smilie

So the program has an infinite loop which keeps it going, as of right now I just simply if exit then $SHELL to get back to prompt, but the program remains.

So the way I've gone about this is by each time exit is run I have

Code:
ps > ps.txt

(suppose I could just pipe ps to the awk, haven't tried that yet)

Code:
awk '/program/ {print $1}' ps.txt

this is printing the processes ID, now I'm trying to store that to a variable and then kill the variable is that possible? Only thing I can think of trying is replace print with
Code:
KILLPID=$1

then after

Code:
kill $KILLPID

but that won't work.

(using bash)

Last edited by Yogesh Sawant; 04-22-2008 at 02:32 AM.. Reason: added code tags
 

10 More Discussions You Might Find Interesting

1. Programming

C program to kill root processes

Hello, First let me start by saying I have searched the forum and read all the SUID stuff but it is not in the neighborhood I am looking for. Here is the problem. We want to grant a non super-user permission to kill root processes but only if the process matches certain criteria. ... (8 Replies)
Discussion started by: TioTony
8 Replies

2. Programming

kill textrdit program

Dear All: I use sun OS system and write a code in c as folloing purpose kill textedit program,but i get some error please give me a great help Thanks. #include <stdlib.h> int main() { const char cTestPrag=" kill -9 `ps -ef | grep textedit | grep -v "grep"| awk '{print $2}'| xargs` "; ... (6 Replies)
Discussion started by: jeter
6 Replies

3. Shell Programming and Scripting

kill multiple instances of the same program

Hi, I know that the answer to this is very simple, since I saw somebody do it some time back..but I forgot how. The problem is, I have multiple instances of the same program running simultaneously and I want to kill them all in a single command. I know that it can be done using awk '{print... (12 Replies)
Discussion started by: ipzig
12 Replies

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

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

6. UNIX for Dummies Questions & Answers

Script to open program and send/execute command in program

Hi, i want to write a script that executes a program (exec?) . this program then requires a filename as input. how do i give it this input in the script so the program will be complete run and close by the script. e.g. exec prog.exe program then asks for filename "enter filename:"... (1 Reply)
Discussion started by: tuathan
1 Replies

7. Shell Programming and Scripting

Kill the running program

Dear All, I have a script which after executing is not stoping when i press ctrl+c. Now i want to Append the script in such a way when i press ctrl+c while execution of the program it should take it as arguements and should kill the script/running program forcefully. I know the command to... (1 Reply)
Discussion started by: akhtar.bhat
1 Replies

8. Shell Programming and Scripting

Kill shell script when host program not running/disk unmounted

I have my Mac OS X program executing a shell script (a script that copies files to a drive). I want to make it so that the shell script automatically kills itself if it finds that the host .app is not running OR kill itself if the drive that it is copying files to has been unmounted. Right now what... (2 Replies)
Discussion started by: pcwiz
2 Replies

9. UNIX for Dummies Questions & Answers

Kill a running program?

Hello i'm trying to make a program which can find a running program on the system and kill it, then repeat that every 5 minutes. The name of the process is given with an argument. I have done this so far, but still not working. if $1 in $(ps -e) ; then kill $(pidof $1) sleep 5m fi (3 Replies)
Discussion started by: petel1
3 Replies

10. UNIX for Dummies Questions & Answers

Kill a program from bash

to kill a program in bash, for instance 'mousepad' I use kill $(pidof mousepad); or pkill mousepad But it only works if we use another bash window; If it is started from the same bash, that does not work: #mousepad;kill $(pidof mousepad); In this case, it looks like mousepad hangs... (7 Replies)
Discussion started by: arpagon
7 Replies
KILL(1) 							   User Commands							   KILL(1)

NAME
kill - send a signal to a process SYNOPSIS
kill [options] <pid> [...] DESCRIPTION
The default signal for kill is TERM. Use -l or -L to list available signals. Particularly useful signals include HUP, INT, KILL, STOP, CONT, and 0. Alternate signals may be specified in three ways: -9, -SIGKILL or -KILL. Negative PID values may be used to choose whole process groups; see the PGID column in ps command output. A PID of -1 is special; it indicates all processes except the kill process itself and init. OPTIONS
<pid> [...] Send signal to every <pid> listed. -<signal> -s <signal> --signal <signal> Specify the signal to be sent. The signal can be specified by using name or number. The behavior of signals is explained in sig- nal(7) manual page. -l, --list [signal] List signal names. This option has optional argument, which will convert signal number to signal name, or other way round. -L, --table List signal names in a nice table. NOTES Your shell (command line interpreter) may have a built-in kill command. You may need to run the command described here as /bin/kill to solve the conflict. EXAMPLES
kill -9 -1 Kill all processes you can kill. kill -l 11 Translate number 11 into a signal name. kill -L List the available signal choices in a nice table. kill 123 543 2341 3453 Send the default signal, SIGTERM, to all those processes. SEE ALSO
kill(2), killall(1), nice(1), pkill(1), renice(1), signal(7), skill(1) STANDARDS
This command meets appropriate standards. The -L flag is Linux-specific. AUTHOR
Albert Cahalan <albert@users.sf.net> wrote kill in 1999 to replace a bsdutils one that was not standards compliant. The util-linux one might also work correctly. REPORTING BUGS
Please send bug reports to <procps@freelists.org> procps-ng October 2011 KILL(1)
All times are GMT -4. The time now is 12:55 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy