Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

[feature request] OS X is there a way to limit using process name instead of pid? #29

Closed
ghost opened this Issue Jan 21, 2014 · 3 comments

Comments

Projects
None yet
1 participant
@ghost

ghost commented Jan 21, 2014

Hey,

First off, thank you, awesome script/program! I have been using it while I was on a linux distro and now on a mac.

My query really is, is it possible to limit a process on the mac using the name of the program.

Scenario:
I mainly use Cpulimit to limit the CPU usage of Handbrake on my mac. I keep having to encode a lot of videos and Cpulimit helps a ton in doing its job.

However, after I finish converting a batch I exit both Cpulimit as well as Handbrake.
The next time I run Handbrake it obviously has a new pid. I then Have to edit the .command shortcut I made for Cpulimit and put in the new pid after checking the pid of HandBrake using the top command.

I would ideally like the shortcut to not have to be edited each time I launch Handbrake. I would like to just double click the Cpulimit shortcut to make it curb the Handbrake process by using the process name instead of the pid.

Example of my .command shortcut:
cd /Users/mymac/Library/Application\ Support/cpulimit/
./cpulimit --p 13827 --limit 77

^That works just fine but requires me to keep editing the pid

I tried:
./cpulimit --e HandBrake --limit 77
./cpulimit -P /Applications/Handbrake --limit 77

and other permutations and combinations before I realized that -e is meant for a .exe and not an .app

Could you please help me out in understanding if what I want is possible.
Thank you Sir.

Jake.

@ghost

ghost commented Jan 26, 2014

Ok, so I know I can get the pid for a a process (Eg:- Handbrake) in terminal using:

ps -A | grep -m1 HandBrake | awk '{print $1}'

How can I use the code above to add it to the argument for example:
./cpulimit --p $1 --limit 77

I am new to terminal, is there a session variable I can set in terminal and will cpulimit accept the value of the session variable, how do I set and get values.

Pl. help!

Owner

opsengine commented Jan 26, 2014

Hi, a workaround would be to run

./cpulimit --p $(pidof Handbrake) --limit 77

I'm not sure why -e would not work on Mac, unfortunately I can't test it as at the moment I don't have a Mac.

@ghost

ghost commented Jan 27, 2014

Hey,

I did a workaround, in case anyone using a Mac wants the simple .command shortcut code it's as below:

cd /Users/mymac/Library/Application\ Support/cpulimit/
HandBrakePID="$(ps -A | grep -m1 HandBrake | awk '{print $1}')"
echo $HandBrakePID
./cpulimit --pid $HandBrakePID --limit 77

Thank you Angelo for replying, appreciate your time :)

Cheers,
Jake.

@ghost ghost closed this Jan 27, 2014

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment