bash- Comportamento Control-C (^ C) / gksudo vs sudo

0

Isto é sobre como a pressão da tecla ctrl + c tem um efeito diferente quando realizada para uma instância gksudo em oposição a uma instância sudo .

Eu executei o seguinte usando gksudo para ler um arquivo de log de falha de instalação:

$ gksudo gedit /tmp/vmware-root/setup-5686.log

Quando eu pretendi fechar a instância do gedit, eu usei um tab para o console (originador) e pressionei ctrl + c . O controle retornou ao console MAS o programa gedit ainda estava funcionando bem.

Esse comportamento é diferente de como sudo se comporta se usado na chamada anterior (o que NÃO recomendo fazer). Usando sudo , ^ C retorna o controle para o console E fecha o programa gedit .

Eu sou novo no Linux ... isso é um comportamento normal e por quê?

    
por Tfb9 06.02.2015 / 00:26

1 resposta

0

Esse é o comportamento normal de um% normalgksudo / gksu , pelo menos no Xubuntu & Linux Mint XFCE. Killing (CTRL + C) gksu gedit (o gksudo é um link para o gksu) deixa o gedit ainda em execução.

man gksu tem esta informação potencialmente útil:

Also notice that the library will decide if it should use su or sudo as backend using the /apps/gksu/sudo-mode gconf key, if you call the gksu command. You can force the backend by using the gksudo command, or by using the --sudo-mode and --su-mode options.

Mas o teste com qualquer uma das opções resulta no mesmo comportamento.

Este teste pode ser esclarecedor:

$ gksu gedit

[em outro terminal]

$ ps -ef|grep [g]edit
UID        PID  PPID  C STIME TTY          TIME CMD
mint      6878  6701  0 23:04 pts/0    00:00:00 gksu gedit
root      6879  6878  0 23:04 ?        00:00:00 /usr/bin/sudo -H -S -p GNOME_SUDO_PASS -u root -- gedit
root      6880  6879  0 23:04 ?        00:00:00 gedit

[Depois de matar (CTRL + C) o gksu gedit no primeiro terminal, ele não para sudo ou gedit ]

$ ps -ef|grep [g]edit
root      6879     1  0 23:04 ?        00:00:00 /usr/bin/sudo -H -S -p GNOME_SUDO_PASS -u root -- gedit
root      6880  6879  0 23:04 ?        00:00:00 gedit

[Matar o primeiro sudo (com outro sudo) mata gedit ]

$ sudo kill 6879
$ ps -ef|grep [g]edit

Assim como a execução de sudo gedit em um terminal iniciará gedit e CTRL + C sudo eliminará gedit . Mas também, se eu fechar o terminal, sudo e gedit continuarão sendo executados.

Então, sudo não se importa se o programa que o chamou ( gksu ou um terminal) for eliminado, e o que for iniciado continuará sendo executado também.

E esses trechos de man sudo também podem ser úteis:

Process model
When sudo runs a command, it calls fork(2), sets up the execution environment as described above, and calls the execve system call in the child process. The main sudo process waits until the command has completed, then passes the command's exit status to the security policy's close function and exits.

Signal handling
When the command is run as a child of the sudo process, sudo will relay signals it receives to the command. Unless the command is being run in a new pty, the SIGHUP, SIGINT and SIGQUIT signals are not relayed unless they are sent by a user process, not the kernel. Otherwise, the command would receive SIGINT twice every time the user entered control-C. Some signals, such as SIGSTOP and SIGKILL, cannot be caught and thus will not be relayed to the command. As a general rule, SIGTSTP should be used instead of SIGSTOP when you wish to suspend a command being run by sudo.

    
por Xen2050 06.02.2015 / 07:38