Forums | MacLife
You are not logged in.
#1 2009-10-26 8:21 pm
- macman2008
- Member

- From: hudson, WI
- Registered: 2008-01-09
- Posts: 49
background help
i'm making an app in automator that starts a command in terminal, and i wnat to make it kill that process when the app quits, here's a screenshot
http://i713.photobucket.com/albums/ww13 … ure1-6.jpg
i'm trying to use the killall command, but it's not working. i can kill it from the process number, but that number changes every time you launch it.
any help/ advice?
Offline
#2 2009-10-27 4:58 am
Re: background help
You can find the process number with ps.
The PID should be the second field.
IE -
Code:
[mpeters@athens tmp]$ ps aux |grep "firefox" |awk '{print $2}'
4162
4174
9811
[mpeters@athens tmp]$shows that I have 3 process ID's with firefox in the name, and prints them.
I'm on Linux, but I assume OS X ps command works the same way.
In her right hand Jenny held the Bible of her mother
Jenny had a pistol in the other
-- Steve Taylor
Offline
#3 2009-10-27 7:27 am
- macman2008
- Member

- From: hudson, WI
- Registered: 2008-01-09
- Posts: 49
Re: background help
So That will show all of the possible pid's? Should I kill all of them on the line, or what?
Offline
#4 2009-10-27 8:22 am
Re: background help
killing them will end the process, though it may not be the best way to do it.
In her right hand Jenny held the Bible of her mother
Jenny had a pistol in the other
-- Steve Taylor
Offline
#5 2009-10-27 12:09 pm
- macman2008
- Member

- From: hudson, WI
- Registered: 2008-01-09
- Posts: 49
Re: background help
and that would be all the possible pid's that program would have?
Offline
#6 2009-10-27 1:20 pm
- dv
- Negusa Negest
- Moderator

- From: Minneapolis, MN
- Registered: 1999-08-30
- Posts: 18078
Re: background help
macman2008 wrote:
and that would be all the possible pid's that program would have?
At that moment, yes.
You obviously can't hard code the PID.
"Now commences the process of cutting off the head, which generally takes from an hour to an hour and a half by an expert workman with a sharp blade." -Reuben Delano, Wanderings and Adventures
Offline
#7 2009-10-27 1:22 pm
- dv
- Negusa Negest
- Moderator

- From: Minneapolis, MN
- Registered: 1999-08-30
- Posts: 18078
Re: background help
But why isn't killall working to kill the process by name? Supposedly, that's what it should be able to do...
/CLI n00b.
"Now commences the process of cutting off the head, which generally takes from an hour to an hour and a half by an expert workman with a sharp blade." -Reuben Delano, Wanderings and Adventures
Offline
#8 2009-10-31 3:48 am
Re: background help
killall should in theory work.
I suspect that there is a better way to accomplish what is trying to be accomplished, there may be a way example to start the process and get the PID of the spawned process when it starts as a return value. There are ways to do that in Linux anyway, Debian uses it to make init scripts for some things that weren't designed to be daemons.
I'd have to look up the details, but that's safer than a killall (or the method I gave) as it avoids the possibility of process name clashes.
In her right hand Jenny held the Bible of her mother
Jenny had a pistol in the other
-- Steve Taylor
Offline
