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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
07-21-2014, 09:18 PM
|
#1
|
Senior Member
Registered: Jul 2009
Distribution: Debian Squeeze
Posts: 1,267
Rep:
|
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.
|
|
|
07-21-2014, 09:26 PM
|
#2
|
Senior Member
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278
|
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.
|
|
|
07-21-2014, 09:28 PM
|
#3
|
LQ Guru
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726
|
Hi,
Quote:
Originally Posted by baronobeefdip
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.
|
|
|
07-22-2014, 09:26 AM
|
#4
|
Senior Member
Registered: Jul 2009
Distribution: Debian Squeeze
Posts: 1,267
Original Poster
Rep:
|
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.
|
|
|
07-22-2014, 04:27 PM
|
#5
|
LQ Addict
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680
|
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.
|
|
|
07-22-2014, 08:20 PM
|
#6
|
LQ Guru
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726
|
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.
|
|
|
07-23-2014, 01:47 AM
|
#7
|
Senior Member
Registered: Jul 2009
Distribution: Debian Squeeze
Posts: 1,267
Original Poster
Rep:
|
I'm in bash, I run the jobs command and nothing displays.
|
|
|
07-23-2014, 02:01 AM
|
#8
|
LQ Addict
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680
|
Quote:
Originally Posted by baronobeefdip
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.
|
|
|
07-23-2014, 02:06 AM
|
#9
|
LQ Guru
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726
|
Hi,
Quote:
Originally Posted by baronobeefdip
I'm in bash, I run the jobs command and nothing displays.
|
really? To demonstrate, please run the following and post the output.
Evo2.
|
|
|
07-24-2014, 09:26 PM
|
#10
|
Senior Member
Registered: Jul 2009
Distribution: Debian Squeeze
Posts: 1,267
Original Poster
Rep:
|
Here is the output
Code:
root@raspberrypi:~# nano &
[1] 2611
root@raspberrypi:~# jobs
[1]+ Stopped nano
root@raspberrypi:~#
|
|
|
07-24-2014, 09:57 PM
|
#11
|
LQ Guru
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726
|
Hi,
Quote:
Originally Posted by baronobeefdip
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.
|
|
|
All times are GMT -5. The time now is 01:47 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|