Stop exe from command line


 
Thread Tools Search this Thread
Top Forums Programming Stop exe from command line
# 1  
Old 07-18-2003
Stop exe from command line

Hi All,
I want to find if a certain exe is running and if it is running i want to stop the execution of this exe (the exe has been created by me) on solaris.
What are the unix command i need to use and can i put these comand in a shell script or create a new exe to do this task (i would prefer an exe cos i need to call this from a browser based frontend, i m not using cgi.)

Thanks in advance

Zing
# 2  
Old 07-18-2003
To kill a process, not a program, you need to know the process id or pid. Manually, you might do "ps -ef | more" and look at the output until you find the process in question. Then you do "kill 123" or whatever. A process can detect this and shut itself down. If that doesn't kill it, then "kill -9 123" is in order.

Since you wrote the program, one useful trick is to have the program write its pid to a file, which by tradition would be called myprog.pid or something. Then you do "kill `cat myprog.pid`".

All of this is possible in C via kill() and getpid().

There are man pages on all of this stuff. So become familiar with commands like:
man -k kill
man -s1 kill
man -s2 kill

But also, if you don't know how to kill a process, I must say that it's premature to writing in C on Unix. I would advise you to read a book on unix programming.

Finally, our rules state:
Quote:
(5) Search the forums database with your keywords before asking.
By simply putting "kill" in as keyword, you would find lots of threads about killing processes.
# 3  
Old 07-21-2003
Hi Zing,

Looking from inside your program you could do the following :

fuser -fu </file/to/program/>

to find any running processes, accessing this file (program)

or

ps -ef | grep <name of program> | grep -v grep | awk '{ print $2}'

This is a possibility too, to find a running process. As you understand this will have to be translated into C. To be honest, I am not this far in Programming C, but it might get you a little closer to your solution.

Please don't use the term exe anymore. It sounds too much like .exe .An executable would be preferred Smilie

@yourservice
David
# 4  
Old 01-29-2009
how to stop a progrom from running in unix or linux

i have to stop a program from running please i want to know how to do this
# 5  
Old 01-29-2009
If you mean you want to terminate the program, please read the above thread. If you want to halt it but not kill it, please make a relevant thread instead of asking new questions in an unrelated one.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read command stop on either EOF or a specific line

I'm trying to stop reading a file until the end of the file is reached or a defined delimiter line is reached. Some how I need to test the fail state of the last 2 commands, not just the last command. echo -e "hello\ngoodbye\n####\ntesting" | while read line; ]; do echo "$line"; done hello... (4 Replies)
Discussion started by: Michael Stora
4 Replies

2. Programming

Why does gdb stop at a different line than “i b” shows while returning from function?

Here is the program I am trying to debug: #include <stdio.h> int i = 5; int main(void) { int x = 3; display(x); return 0; } void display(int x) { for ( i=0; i<x; ++i ) { printf("i is %d.\n", i); } }This code is coming from here Peter's gdb Tutorial: Stepping... (2 Replies)
Discussion started by: ijustneeda
2 Replies

3. Shell Programming and Scripting

Command to stop all the cron jobs

Hi All, Please provide the command to stop all the cron jobs. Thanks in Advance Regards, Sindu (2 Replies)
Discussion started by: indira_s
2 Replies

4. UNIX for Dummies Questions & Answers

Command to stop sub directories being counted?

I'm trying to count the number of directories in a folder but I don't want to count the sub directories. So far I have this: find -type d | wc -l Is there a parameter to stop counting sub directories ? Thanks (5 Replies)
Discussion started by: Ultima
5 Replies

5. Shell Programming and Scripting

Need to stop script for until present command excuted

Hi, Basically I am running a script in another script. #!/bin/sh DIRECTORY="/export/home/scripts" CURDATIME=`date '+%m%d%y_%H%M%S'` LOG_FILE="${DIRECTORY}/${CURDATIME}_abc.out" echo "ABC Delta Script started at `${CURDATIME}`" > $LOG_FILE cd ${DIRECTORY} sh ./abcDeltaRun.sh >>... (1 Reply)
Discussion started by: tnrchinna
1 Replies

6. Shell Programming and Scripting

How to stop Sqlplus command from printing db connection details

Hi, Could someone tell me how to stop SQLPLUS command from printing the connection details in the console. Below is the lines i get in console when executing the sqlplus... SQL*Plus: Release 10.2.0.1.0 - Production on Wed Mar 9 03:31:03 2011 Copyright (c) 1982, 2005, Oracle. All rights... (2 Replies)
Discussion started by: funonnet
2 Replies

7. Shell Programming and Scripting

Help with script to stop a user giving kill command on a server!!

Hi, I am new to shell scripting and want to create a script with the follwoing description: I want to restrict the users from giving a kill command on a unix server. The server have a restricted logins with login id and passwords. I want a script that will find out if a user has given a... (9 Replies)
Discussion started by: shell_scripting
9 Replies

8. UNIX for Dummies Questions & Answers

grep question: stop search from finding entire line

Sorry for the title, I really don't know how to word this question or what to even search for. I tried "grep one match", "grep 1 match", "stop grep" on both google and here and haven't found something that helps, so here I go: I have a file that's about 1.5 million lines long, every line looks... (3 Replies)
Discussion started by: rmoakler
3 Replies

9. Shell Programming and Scripting

Stop awk adding a new line

In a loop, I want to append some text to a file without generating a new line (and then force a new line before re-iterating the loop). In the code below the first 'echo' command is OK as it uses '--n' for no new line. For the 'awk' line I *thought* I could solve it by using printf rather than... (1 Reply)
Discussion started by: TobyR
1 Replies

10. Programming

how To edit exe to insert a serial no wich can be usd by runing exe

At time of installation I have to open the resource. and i have to insert a string serial number in the exe. please provide me code to edit the exe (in solaris) to insert a serial number which can be used by exe at run time. (6 Replies)
Discussion started by: ssahu
6 Replies
Login or Register to Ask a Question