You are not logged in.
I'm running a version of Mendeley (citation manager) which has a bug that causes it to constantly use 100% of one of my CPUs.
To get around this, I went to define a command to cpu-throttle it when run, using cpulimit .
In order to allow menderley some time to syncronize files before throttling, I run
mendeleydesktop & (sleep 20; cpulimit -i -l 10 -p $!)in a terminal. As expected, this launches Mendeley and throttles cpu usages to 10% after 30 seconds (mendeley's PID is passed to cpulimit with $!).
To automate this, I add
mendelazy(){
mendeleydesktop & (sleep 20; cpulimit -i -l 10 -p $!) &>/dev/null
}to .bashrc, reload it with source .bashrc, and modify /home/ahura/.local/share/applications/mendeleydesktop.desktop so the newly defined command is instead called, by changing the Exec line into Exec=mendelazy.
However, while running mendelazy in a terminal produces the expected result, running mendeley from the 'start' menu (using Cinnamon), cpu usage remains at 100%.
If anyone can help me understand why this is, I'd be very grateful.
To be clear I AM NOT looking for information on how to downgrade mendeley or fix the original bug - I am curious about the behavior described above and wish to understand it.
Last edited by ahura (2018-05-29 16:19:52)
Offline
The round brackets execute the `sleep` and `cpulimit` commands in a subshell -- I'm guessing there's different behaviour between subshells are their parents in an interactive shell vs non-interactive. There should be no need to use the subshell in your function; try this:
mendelazy(){
mendeleydesktop &
sleep 20
cpulimit -i -l 10 -p $(pidof mendeleydesktop)
}Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
It tried doing that (except using $(pidof /opt/mendeleydesktop/lib/mendeleydesktop/libexec/mendeleydesktop.x86_64) as that is the misbehaving process).
Again, it works as expected when launched in a terminal, but using the menu shortcut doesn't throttle.
Offline
Again, it works as expected when launched in a terminal, but using the menu shortcut doesn't throttle.
Does the function work when run from a terminal, or do you mean only manually entering each of those commands works?
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Does the function work when run from a terminal, or do you mean only manually entering each of those commands works?
Yes, simply typing mendelazy in a terminal after source .bashrc produces the expected result.
Offline
Ok, then what's in the menu shortcut that doesn't work? How does it not work? Are you sure it runs the function at all? Does it start an interactive shell (to even have the function defined)?
I just reread your first post, and changing the Exec line of a desktop file to the name of a shell function will most certainly not work ... at all. So I gather that desktop file is not even being used by your menu/launcher. You either need to put the content of that function in a script called mendelazy in your $PATH, or you need the Exec line to run an interactive shell (to source bashrc) and then run the function (the former would make much more sense to me).
Last edited by Trilby (2018-05-29 15:24:00)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Create a custom menu entry that starts mendelazy .
If that works, cinnamon mendeley menu entry uses the default *.desktop instead of your changed one.
Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.
clean chroot building not flexible enough ?
Try clean chroot manager by graysky
Offline
You either need to put the content of that function in a script called mendelazy in your $PATH
I tried doing this - specifically, I created /home/ahura/.scripts/mendelazy with the contents
mendeleydesktop &
sleep 5
cpulimit -i -l 10 -p $(pidof /opt/mendeleydesktop/lib/mendeleydesktop/libexec/mendeleydesktop.x86_64)ran chmod +x on it, and added export PATH="$HOME/.scripts:$PATH" in bashrc, and removed the function definition from bashrc. I rebooted just to make sure the old function was gone.
Once again, running mendelazy in terminal works as expected, whereas the menu item doesn't. Similarly, adding the full path (Exec=/home/ahura/.scripts/mendelazy) in /home/ahura/.local/share/applications/mendeleydesktop.desktop also doesn't change anything. It seems the menu item just does the same thing no matter what I put in the .desktop file.
Last edited by ahura (2018-05-29 16:06:39)
Offline
Okay, I tried simply deleting the menu shortcut and creating a new one executing the script, and this works. Thanks for the inputs.
To summarize solution for others with the same problem:
1) install cpulimit
2) create script somewhere with contents
mendeleydesktop &
sleep 5
cpulimit -i -l 10 -p $(pidof /opt/mendeleydesktop/lib/mendeleydesktop/libexec/mendeleydesktop.x86_64)3) make script executable (chmod +x <filename>)
4) Delete existing menu item and create a new the runs the script.
Offline
Did you check to make sure the right desktop file is being used? What did htop say with regard to the processes you were running -- did your shellscript show up as the parent process for mendeleydesktop?
Managing AUR repos The Right Way -- aurpublish (now a standalone tool)
Offline