aspose file tools*
The moose likes Linux / UNIX and the fly likes learner Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "learner" Watch "learner" New topic
Author

learner

crisis ofid
Greenhorn

Joined: Oct 22, 2004
Posts: 5
How to stop program running in background
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

If the program in the background is cupsd:

will print a table of processes with commandname 'cupsd'.
There is a number, called 'pid' - the process-id.
with this number - assuming 1234, you may kill it:
, which is a friendly way to tell the program to stop. It may try to finish in a nice way, closing open files, database connections, ...
After two or three seconds, look whether it was killed successfully:

If it is still running, kill it with

Read 'man kill' and 'man ps' to find out more on this commands.

You will need some time to understand everything, but understanding a bit more from time to time in small steps will lead you to deeper knowledge.

Last but not least - we don't like crossposting.
But we like specific subjects, like 'stop a background process' - not 'learner'. We are all learners.

[ October 22, 2004: Message edited by: Stefan Wagner ]
[ October 22, 2004: Message edited by: Stefan Wagner ]

http://home.arcor.de/hirnstrom/bewerbung
crisis ofid
Greenhorn

Joined: Oct 22, 2004
Posts: 5
Thanks
It was my first time will take care from next time
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

Also check out "killall".

However, cupsd is a daemon, which is equivalent to a Windows Service, so you probably don't want to do a kill, you probably want it to shut down clean (unless it's locked up or something). For that, do the following:

/etc/init.d/cupsd stop

Or, for Red Hat/Fedora this also works:

/sbin/service cupsd stop


Customer surveys are for companies who didn't pay proper attention to begin with.
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

a very good hint!
look into /etc/init.d/ whether the program is located there, and - cupsd or whatever - the 'stop' option should be used.
vaibhav dobriyal
Greenhorn

Joined: Oct 28, 2004
Posts: 2
i think the program can be brought into foreground by
$fg
and then simply ctrl+c

i think this should work!

dobi


First there was a problem,<br />then there was a solution and then...bang there were problems more than ever before...C
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
yes, that can work.
The full sequence is
1$ jobs
2$ fg <number>
3$ ^C

1 gives a list of jobs running as child processes for this terminal.
2 brings one of these to the foreground
3 sends a terminate signal to this program. Whether the program recognises that signal depends on how it's programmed.

It doesn't work for jobs that were started from other terminals (for example on system startup) though.


42
crisis ofid
Greenhorn

Joined: Oct 22, 2004
Posts: 5
But i have started jobs from other terminals in background. SO how to proceed to stop it.
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
use ps -a (or ps -A if they were started by another user), grep the output to get the PID of the process you want to kill, and use kill to kill it.

For example $ ps -a | grep 'rlogin' | more will retrieve all PIDs for rlogin processes.
$kill -15 124535 will send a kill signal to process 124535, kill -9 124535 will terminate process 124535 with extreme prejudice (not even giving it time to clean up after itself).
 
 
subject: learner