LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Laptop and Netbook (https://www.linuxquestions.org/questions/linux-laptop-and-netbook-25/)
-   -   Stop processes when on battery to save power (https://www.linuxquestions.org/questions/linux-laptop-and-netbook-25/stop-processes-when-on-battery-to-save-power-674545/)

unihiekka 10-06-2008 07:17 AM

Stop processes when on battery to save power
 
Hi!

Does anyone know if it is possible to stop certain processes from being loaded (by a short start-up script) when one boots the laptop? I have several processes that should be loaded when starting with my laptop plugged in, but when I am working on my battery I don't want them to start (e.g. trackerd, network manager, update notifier, etc.), since they slow my laptop down or are not needed, as I don't have internet access.

Any help appreciated!

David the H. 10-06-2008 08:08 AM

You should be able to use ivman. It uses hal to detect changes in the system, such as when the device is on battery power, and will run whatever command or script you want on selected events. Not just for start-up, but for any change in status, so you can have it start and stop processes any time you switch power supplies.

unihiekka 10-06-2008 03:50 PM

I have solved it rather easily by creating a startup script that checks whether the battery or the AC power is used (with grep) and depending on that outcome loads the minimal processes or all, respectively. I then added that script to the start up (preferences>sessions) and deselected the previously selected items (as they are now incorporated in the script).

It does not work with the HAL daemon and does not reactive or deactivate while running if one plugs or pulls out the power cable, but it works for me.

I would be interested to know how to do it with the lvman method, just for good order.

BallsOfSteel 10-06-2008 05:23 PM

If you have an Intel based laptop, there is a program called Powertop and when run from a terminal, it will tell you which processes are using the most power.

Kingtiger01 10-06-2008 06:10 PM

unihiekka, being said that you fixed youre own problem. Would you please Post you're script. for if some one else has a Similar issue, they may use you're solution.

unihiekka 10-07-2008 02:54 AM

You absolutely right, your majesty! :D

Here's my script:

Code:

#!/bin/bash
#Start with minimum processes on battery power
if grep -q off-line /proc/acpi/ac_adapter/ACAD/state
 then
 #Here come the programmes you wish to start after login (on battery power)
 #For example:
 gnome-power-manager
 #If they are in your $PATH you can just give their binary names, otherwise you have to write the full paths to the applications
elif grep -q on-line /proc/acpi/ac_adapter/ACAD/state
 then
 #Here come the programmes you wish to start after login (on AC power)
 #Examples:
 gnome-power-manager
 nm-applet --sm-disable &
 restricted-manager --check &
 trackerd &
 update-notifier &
 gnome-volume-manager --sm-disable &
 #etc. 
fi

Go to System > Preferences > Sessions and add it to your startup programmes (first tab). If you always login in English (or some other languague that actually never changes), then you can deselect/remove "User folders update", which is only useful when you change languages and would like your folders to have localized names. If you don't use magnifiers and the like, you can rest assured when you deselect/remove "Visual". This might help the startup process to be slightly quicker.

Actually, for this script to be useful, you have to deselect all startup programmes and add their respective binary names to the script. You can find those names if you click on the items in the list and then click on edit. Just copy-paste the "command" to the correct section of the script (with battery or AC powered). I have added gnome-power-manager to both parts, since I want to know how much battery time there is left (on battery) or how much longer it will take to fully charge my battery (on AC). But you are free to edit the script as much as you like. Just make sure that it is the only selected item in the Sessions list (the others don't have to be removed, merely deselected) and that all programmes that you wish to start are in the script [if this script is selected and the ones that the script should start, then the script restarts these programmes, which in itself is not terrible, but slow and not wise, because the intention of my script is to remove unnecessary programmes at startup]. Then it should do what you hope it to do.

I hope that helps!

Kingtiger01 10-07-2008 03:21 PM

thank you for taking the time to share youre solutions with us. im sure it will help some one very much!

pinballwizard66 10-12-2008 04:18 PM

yea this thing is very nice, i might even use it when i have classes and no way to plug in the power cord. thanks a lot

Debian Development


All times are GMT -5. The time now is 11:56 PM.