LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-21-2014, 09:18 PM   #1
baronobeefdip
Senior Member
 
Registered: Jul 2009
Distribution: Debian Squeeze
Posts: 1,267

Rep: Reputation: 32
How do I kill a command that I am running in background


I have installed raspian and I have been running commands and processes in the background via ssh. I want to be able to SSH back into the pi and kill the process I told it to run in the background so I can start a new one. Some of the typical methods found on google searches don't work but I am open so suggestions.
 
Old 07-21-2014, 09:26 PM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1693Reputation: 1693Reputation: 1693Reputation: 1693Reputation: 1693Reputation: 1693Reputation: 1693Reputation: 1693Reputation: 1693Reputation: 1693Reputation: 1693
So ssh back into the pi and kill the process. Use pgrep or ps to find its pid number and use kill or pkill to kill the process.

If you mean you want to keep track of the pid of background processes you create to later kill them without having to look them up, you will have to make your own pid file:

Code:
> your_pids          # clear pid file
your_command &       # run command in background
echo $! >> your_pids # print pid to file
Then when you want to kill all your background processes you created

Code:
while read line
do
    pkill $line
    echo "Killed process $line"
done < your_pids

Last edited by szboardstretcher; 07-21-2014 at 09:32 PM.
 
Old 07-21-2014, 09:28 PM   #3
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,720

Rep: Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704
Hi,
Quote:
Originally Posted by baronobeefdip View Post
I have installed raspian and I have been running commands and processes in the background via ssh. I want to be able to SSH back into the pi and kill the process I told it to run in the background so I can start a new one.
That should be possible.
Quote:
Some of the typical methods found on google searches don't work but I am open so suggestions.
I could list some typical methods, but presumably the "don't work", so it is best you tell us what you tried and what happened.

Evo2.
 
Old 07-22-2014, 09:26 AM   #4
baronobeefdip
Senior Member
 
Registered: Jul 2009
Distribution: Debian Squeeze
Posts: 1,267

Original Poster
Rep: Reputation: 32
Raspbian is very strange, in saying that many if the basic commands found in a typical Debian and Ubuntu installation are absent (I guess that was done to preserve space on the SD card). I can't run a command like nslookup, and traceroute. What was really getting to be was the absence of the jobs command. I want to be able to bring the process back to the foreground but I am unable to do that because the jobs command isn't present on the operating system. What package do I need to install in order to have the command. basically speaking, the jobs command wasn't present in the PI, How do I get it installed in the pi because I don't know what aptitude installation I should run in order to get it going on the pi.
 
Old 07-22-2014, 04:27 PM   #5
273
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
Jobs appears to be working just fine on my Pi -- which version of Raspbian are you using? You say you're SSHing into the Pi then exiting and going back -- surely that will loose track of your running processes? If you just want to return to the same terminal session that you left when you disconnected know the Pi you may want to use screen on the Pi.
 
Old 07-22-2014, 08:20 PM   #6
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,720

Rep: Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704
Hi,

jobs is a shell builtin. What shell are you using? If some programs that you want are missing just go ahead and "apt-get install" them.

Evo2.
 
Old 07-23-2014, 01:47 AM   #7
baronobeefdip
Senior Member
 
Registered: Jul 2009
Distribution: Debian Squeeze
Posts: 1,267

Original Poster
Rep: Reputation: 32
I'm in bash, I run the jobs command and nothing displays.
 
Old 07-23-2014, 02:01 AM   #8
273
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
Quote:
Originally Posted by baronobeefdip View Post
I'm in bash, I run the jobs command and nothing displays.
As far as I am aware that is normal behaviour for jobs -- once you disconnect your session you lose your jobs list. As I mentioned one way around this is to use screen (I hear tmux may be better though) and return to a session.
 
Old 07-23-2014, 02:06 AM   #9
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,720

Rep: Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704
Hi,
Quote:
Originally Posted by baronobeefdip View Post
I'm in bash, I run the jobs command and nothing displays.
really? To demonstrate, please run the following and post the output.
Code:
nano &
jobs
Evo2.
 
Old 07-24-2014, 09:26 PM   #10
baronobeefdip
Senior Member
 
Registered: Jul 2009
Distribution: Debian Squeeze
Posts: 1,267

Original Poster
Rep: Reputation: 32
Here is the output
Code:
root@raspberrypi:~# nano &
[1] 2611
root@raspberrypi:~# jobs
[1]+  Stopped                 nano
root@raspberrypi:~#
 
Old 07-24-2014, 09:57 PM   #11
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,720

Rep: Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704
Hi,
Quote:
Originally Posted by baronobeefdip View Post
Here is the output
Code:
root@raspberrypi:~# nano &
[1] 2611
root@raspberrypi:~# jobs
[1]+  Stopped                 nano
root@raspberrypi:~#
Ok, so that works as expected. Can you post something that demonstrates the problem?

Evo2.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Kill all Background Jobs jwprz70 Linux - Newbie 10 05-12-2010 02:29 AM
kenel panic not syncing: attempted to kill init after running fsck command wabee Linux - Newbie 1 05-08-2009 09:22 AM
Perl: Running Command line apps in background and capturing output s0l1dsnak3123 Programming 8 03-28-2008 02:24 PM
script/command to kill processes running on particular port varunbihani Linux - General 2 07-08-2005 04:35 AM
How can I see what process are running and how to I kill them? (command line). brynjarh Linux - Newbie 4 07-07-2004 04:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration