Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Question con !
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index French
View previous topic :: View next topic  
Author Message
DuF
Advocate
Advocate


Joined: 09 Dec 2002
Posts: 2687
Location: Paris

PostPosted: Wed Feb 26, 2003 12:55 am    Post subject: Question con ! Reply with quote

En fait l'autre jour, je suis arrivé sur mon ordi qui reste allumé, et j'ai pris un xterm ouvert, dans lequel j'étais loggé en root, je fais exit pour retourner dans mon user de base et qd j'ai voulu sortir par un autre exit, en fait me suis retrouvé en root...
J'avais tout simplement fait successivement des su -, su user, su -, su user, su -, su user... au moins une dizaine de fois... un peu idiot de ma part en somme :?

Ma question est => est-il possible de savoir combien de su on a lancé dans la console ou xterm en cours ?
Back to top
View user's profile Send private message
bsolar
Bodhisattva
Bodhisattva


Joined: 12 Jan 2003
Posts: 2764

PostPosted: Wed Feb 26, 2003 1:04 am    Post subject: Reply with quote

Each su should be a separate process, so you can do ps to see how many are there. You can see to what console belongs each su looking at the TTY.
I.e:
Code:
# ps -al
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
4 S     0 16537 16333  0  76   0 -   511 wait4  pty/s0   00:00:00 su
0 S     0 16540 16537  0  75   0 -   543 wait4  pty/s0   00:00:00 bash
4 S     0 16617 16540  0  76   0 -   511 wait4  pty/s0   00:00:00 su
0 S     0 16620 16617  0  75   0 -   543 wait4  pty/s0   00:00:00 bash
4 S     0 16625 16620  0  76   0 -   511 wait4  pty/s0   00:00:00 su
0 S     0 16628 16625  0  75   0 -   543 schedu pty/s0   00:00:00 bash
4 S     0 16641 16636  0  76   0 -   511 wait4  pty/s1   00:00:00 su
0 S     0 16644 16641  0  75   0 -   543 wait4  pty/s1   00:00:00 bash
0 R     0 16650 16644  0  76   0 -   831 -      pty/s1   00:00:00 ps

here I have 2 conosles, one with a su and the other with 3 su...
_________________
I may not agree with what you say, but I'll defend to the death your right to say it.
Back to top
View user's profile Send private message
DuF
Advocate
Advocate


Joined: 09 Dec 2002
Posts: 2687
Location: Paris

PostPosted: Wed Feb 26, 2003 1:19 am    Post subject: Reply with quote

thanks for your good answer to my very very very stupid question !
Merci pour ta bonne réponse à ma très très très stupide question !
Back to top
View user's profile Send private message
bsolar
Bodhisattva
Bodhisattva


Joined: 12 Jan 2003
Posts: 2764

PostPosted: Wed Feb 26, 2003 1:23 am    Post subject: Reply with quote

DuF wrote:
thanks for your good answer to my very very very stupid question !
Merci pour ta bonne réponse à ma très très très stupide question !


That was not a stupid question, IMHO, btw I'm happy to be helful :wink:
_________________
I may not agree with what you say, but I'll defend to the death your right to say it.
Back to top
View user's profile Send private message
DuF
Advocate
Advocate


Joined: 09 Dec 2002
Posts: 2687
Location: Paris

PostPosted: Wed Feb 26, 2003 1:27 am    Post subject: Reply with quote

maybe it's not a stupid question, but if I have search myself 30s I will have answer myself, it's for this that I think it's a stupid question...
Thx for your help ;)
Back to top
View user's profile Send private message
ttgeub
Guru
Guru


Joined: 20 Jan 2003
Posts: 494
Location: Eindhoven

PostPosted: Wed Mar 05, 2003 11:46 am    Post subject: Reply with quote

Pour avoir le nombre de shell imbrique il suffit en realite de faire
echo $SHLVL
Back to top
View user's profile Send private message
DuF
Advocate
Advocate


Joined: 09 Dec 2002
Posts: 2687
Location: Paris

PostPosted: Wed Mar 05, 2003 1:06 pm    Post subject: Reply with quote

Qu'entends par shell imbriqué ?
car lorsque je lance echo $SHLVL sur un nouveau term, il me dit 6, alors que ce term est nouveau !
Moi ma question c'est plus combien de session ont été lancés dans un même terminal !

Sinon c'est quand même bon à savoir ton information !
thx !
Back to top
View user's profile Send private message
ttgeub
Guru
Guru


Joined: 20 Jan 2003
Posts: 494
Location: Eindhoven

PostPosted: Wed Mar 05, 2003 2:46 pm    Post subject: Reply with quote

Issu de man bash :

SHLVL (NDT : Lire SH LVL - Shell Level - Niveau d'interpréteur) Incrémenté de 1 à chaque invocation d'une instance de bash.

Chaque shell fait la meme chose donc on a ainsi le nombre de shell lance les uns sur les autres. (imbriqué quoi !)

Normalement lorsque tu lances un terminal tu dois avoir 1 et pas 6 ce qui me semble extrement bizzare
Back to top
View user's profile Send private message
DuF
Advocate
Advocate


Joined: 09 Dec 2002
Posts: 2687
Location: Paris

PostPosted: Wed Mar 05, 2003 6:58 pm    Post subject: Reply with quote

pourtant c'est bien ce que j'ai !
En fait que j'en lance 1 ou 10 des xterm ou rxvt, la valeur reste toujours à 6 !
Doit y avoir un souci qqpart :)
Back to top
View user's profile Send private message
ghoti
Advocate
Advocate


Joined: 30 Dec 2002
Posts: 3634
Location: Belgium

PostPosted: Wed Mar 05, 2003 8:58 pm    Post subject: Reply with quote

En utilisant ps axf, on visualise plus facilement ce qui se passe depuis la console jusqu'au lancement de X :
Code:
 2056 vc/1     S      0:00 login -- root
 2139 vc/1     S      0:00  \_ -bash     =================================> 1
 2146 vc/1     S      0:00      \_ /bin/sh /usr/X11R6/bin/startx ==================> 2
 2157 vc/1     S      0:00          \_ xinit /etc/X11/xinit/xinitrc --
 2158 ?        R<L    7:44              \_ X :0
 2163 vc/1     S      0:00              \_ /bin/sh /etc/X11/Sessions/kde-3.1 ===========>3
 2274 vc/1     S      0:00                  \_ /bin/sh --login /usr/kde/3.1/bin/ ==========>4
 2351 vc/1     S      0:00                      \_ kwrapper ksmserver

Lorsque l'environnement graphique est finalement opérationnel, on a déjà 4 niveaux imbriqués de shell.
Sous kde, si je lance la commande xterm, kde l'exécute via un shell (donc de niveau 5) et le shell du xterm proprement dit affiche donc le niveau 6.
Code:
 2358 ?        S      0:07 kdeinit: kdesktop         
12847 ?        S      0:00  \_ xterm    =================>5 (via shell "implicite" ?)
12848 pts/0    S      0:00      \_ bash =================>6
12851 pts/0    R      0:00          \_ ps axf

Par contre, si je lance konsole, il obtient le niveau 5 et non 6 (tiendrait à la manière dont kde exécute ses propres composants ??)
Code:
12852 ?        S      0:00  \_ kdeinit: konsole
12853 pts/0    S      0:00      \_ /bin/bash ============>5
12856 pts/0    R      0:00          \_ ps axf

Si, à partir du xterm de niveau 6, je lance plusieurs xterms différents en rendant chaque fois la main, le xterm "père" renvoie toujours le même level 6.
Par contre, si je lance une nouvelle instance de bash, le niveau est incrémenté :
Code:
bash-2.05b# echo $SHLVL
6
bash-2.05b# xterm &
[1] 12873
bash-2.05b# echo $SHLVL
6
bash-2.05b# xterm &
[2] 12877
bash-2.05b# echo $SHLVL
6
bash-2.05b# bash
bash-2.05b# echo $SHLVL
7
bash-2.05b# bash
bash-2.05b# echo $SHLVL
8
bash-2.05b#

Les xterm "fils" lancés ci-dessus ont tous le niveau 7 car ils sont tous lancés à partir du même niveau 6.
ps axf donne la situation suivante pour le code ci-dessus :
Code:
 2358 ?        S      0:07 kdeinit: kdesktop       
12869 ?        S      0:00  \_ xterm
12870 pts/0    S      0:00      \_ bash ============> 6
12873 pts/0    S      0:00          \_ xterm
12874 pts/1    S      0:00          |   \_ bash =========> 7
12877 pts/0    S      0:00          \_ xterm
12878 pts/2    S      0:00          |   \_ bash =========> 7
12881 pts/0    S      0:00          \_ bash ===========> 7   
12884 pts/0    S      0:00              \_ bash =========> 8
12887 pts/0    R      0:00                  \_ ps axf
Back to top
View user's profile Send private message
DuF
Advocate
Advocate


Joined: 09 Dec 2002
Posts: 2687
Location: Paris

PostPosted: Wed Mar 05, 2003 11:27 pm    Post subject: Reply with quote

merci beaucoup pour ces explications très claires, je n'avais pas regardé le man de ps, donc pas vraiment au courant de ces possibilités !
Encore un grand merci à toi pour ces éclaircissements forts utiles !
Back to top
View user's profile Send private message
dioxmat
Bodhisattva
Bodhisattva


Joined: 04 May 2002
Posts: 709
Location: /home/mat

PostPosted: Thu Mar 06, 2003 2:34 pm    Post subject: Reply with quote

un autre petit truc interessant, en utilisant SHLVL, c'est la variable rprompt de tcsh. personellement je mets dedans le nombre de sous shells apres le premier. ca me permet de voir d'un seul coup d'oeil ce genre de choses...
_________________
mat
Back to top
View user's profile Send private message
DuF
Advocate
Advocate


Joined: 09 Dec 2002
Posts: 2687
Location: Paris

PostPosted: Thu Mar 06, 2003 5:53 pm    Post subject: Reply with quote

y a une manière de faire un équivalent avec bash ?
Back to top
View user's profile Send private message
Doudou
Apprentice
Apprentice


Joined: 10 Jan 2003
Posts: 286
Location: Paris, France

PostPosted: Fri Mar 07, 2003 7:49 am    Post subject: Reply with quote

excellent l'options f de la commande ps, je ne connaissais pas non plus!! :D
Back to top
View user's profile Send private message
ghoti
Advocate
Advocate


Joined: 30 Dec 2002
Posts: 3634
Location: Belgium

PostPosted: Fri Mar 07, 2003 6:22 pm    Post subject: Reply with quote

DuF wrote:
y a une manière de faire un équivalent avec bash ?
On peut utiliser la variable $PS1.
Essaie un peu ça:
Code:
export PS1='$SHLVL'-$PS1
Ensuite tu lances un nouveau shell à partir de ton shell courant...
Back to top
View user's profile Send private message
DuF
Advocate
Advocate


Joined: 09 Dec 2002
Posts: 2687
Location: Paris

PostPosted: Sat Mar 08, 2003 4:54 am    Post subject: Reply with quote

effectivement ça marche bien, merci ghoti !
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index French All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum