Como desligar o seu Linux via botão power ? Confira e veja como é simples!

Emanuel Negromonte
3 minutos de leitura
Isso mesmo, com o Gnome3 e outros gerenciadores, algumas pessoas tem tido problemas ao desligar o seu computador, que tal pressionar o botão power e o seu linux desligar?

A solução é simples:

1º Copie e cole o código abaixo em um arquivo com nome de acpi-power-button-monitor.c em qualquer lugar de seu computador (no meu caso eu copiei na ~/). Não copie a linha 51!
/* ACPI power button monitor.
* Copyright (c) 2008 Paulo Matias
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR “AS IS” AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include
#include
#include
int main() {
static char buf[128];
FILE *fp;
assert((fp = fopen(“/proc/acpi/event”, “r”)));
while(1) {
fgets(buf, sizeof(buf), fp);
if(!strcmp(strtok(buf, ” “), “button/power”)) {
system(“halt”);
break;
}
}
fclose(fp);
return 0;
}

2º Vamos agora compilar o código com o comando:

gcc -Os acpi-power-button-monitor.c -o acpi-power-button-monitor

3º Vamos copiar o arquivo compilado ” programa já pronto para execução ” para a pasta padrão dos programas da sua distribuição. No caso do Archlinux esta pasta fica em /usr/bin:

mv acpi-power-button-monitor /usr/bin

chmod 755 /usr/bin/acpi-power-button-monitor

Agora por fim, você precisa inserir esta aplicação para iniciar com o boot, recomendamos o artigo abaixo, lembramos que esta aplicação deve consumir em torno de 380MB de RAM.
Share This Article
Follow:
Fundador do SempreUPdate. Acredita no poder do trabalho colaborativo, no GNU/Linux, Software livre e código aberto. É possível tornar tudo mais simples quando trabalhamos juntos, e tudo mais difícil quando nos separamos.