View previous topic :: View next topic |
Author |
Message |
DuF Advocate
![Advocate Advocate](/images/ranks/rank-G-1-advocate.gif)
![](images/avatars/500f78f33e18696e0a90f.jpg)
Joined: 09 Dec 2002 Posts: 2687 Location: Paris
|
Posted: Wed Feb 26, 2003 12:55 am Post subject: Question con ! |
|
|
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 |
|
![](templates/gentoo/images/spacer.gif) |
bsolar Bodhisattva
![Bodhisattva Bodhisattva](/images/ranks/rank-bodhisattva.gif)
![](images/avatars/806967053f23f4aede2da.jpg)
Joined: 12 Jan 2003 Posts: 2764
|
Posted: Wed Feb 26, 2003 1:04 am Post subject: |
|
|
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 |
|
![](templates/gentoo/images/spacer.gif) |
DuF Advocate
![Advocate Advocate](/images/ranks/rank-G-1-advocate.gif)
![](images/avatars/500f78f33e18696e0a90f.jpg)
Joined: 09 Dec 2002 Posts: 2687 Location: Paris
|
Posted: Wed Feb 26, 2003 1:19 am Post subject: |
|
|
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 |
|
![](templates/gentoo/images/spacer.gif) |
bsolar Bodhisattva
![Bodhisattva Bodhisattva](/images/ranks/rank-bodhisattva.gif)
![](images/avatars/806967053f23f4aede2da.jpg)
Joined: 12 Jan 2003 Posts: 2764
|
Posted: Wed Feb 26, 2003 1:23 am Post subject: |
|
|
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 :wink:](images/smiles/icon_wink.gif) _________________ I may not agree with what you say, but I'll defend to the death your right to say it. |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
DuF Advocate
![Advocate Advocate](/images/ranks/rank-G-1-advocate.gif)
![](images/avatars/500f78f33e18696e0a90f.jpg)
Joined: 09 Dec 2002 Posts: 2687 Location: Paris
|
Posted: Wed Feb 26, 2003 1:27 am Post subject: |
|
|
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 ![Wink ;)](images/smiles/icon_wink.gif) |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
ttgeub Guru
![Guru Guru](/images/ranks/rank_rect_3.gif)
![](images/avatars/gallery/Marvel/Marvel_-_Spiderman.gif)
Joined: 20 Jan 2003 Posts: 494 Location: Eindhoven
|
Posted: Wed Mar 05, 2003 11:46 am Post subject: |
|
|
Pour avoir le nombre de shell imbrique il suffit en realite de faire
echo $SHLVL |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
DuF Advocate
![Advocate Advocate](/images/ranks/rank-G-1-advocate.gif)
![](images/avatars/500f78f33e18696e0a90f.jpg)
Joined: 09 Dec 2002 Posts: 2687 Location: Paris
|
Posted: Wed Mar 05, 2003 1:06 pm Post subject: |
|
|
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 |
|
![](templates/gentoo/images/spacer.gif) |
ttgeub Guru
![Guru Guru](/images/ranks/rank_rect_3.gif)
![](images/avatars/gallery/Marvel/Marvel_-_Spiderman.gif)
Joined: 20 Jan 2003 Posts: 494 Location: Eindhoven
|
Posted: Wed Mar 05, 2003 2:46 pm Post subject: |
|
|
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 |
|
![](templates/gentoo/images/spacer.gif) |
DuF Advocate
![Advocate Advocate](/images/ranks/rank-G-1-advocate.gif)
![](images/avatars/500f78f33e18696e0a90f.jpg)
Joined: 09 Dec 2002 Posts: 2687 Location: Paris
|
Posted: Wed Mar 05, 2003 6:58 pm Post subject: |
|
|
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 ![Smile :)](images/smiles/icon_smile.gif) |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
ghoti Advocate
![Advocate Advocate](/images/ranks/rank-G-1-advocate.gif)
![](images/avatars/15463172846237c094abba7.jpg)
Joined: 30 Dec 2002 Posts: 3636 Location: Belgium
|
Posted: Wed Mar 05, 2003 8:58 pm Post subject: |
|
|
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 |
|
![](templates/gentoo/images/spacer.gif) |
DuF Advocate
![Advocate Advocate](/images/ranks/rank-G-1-advocate.gif)
![](images/avatars/500f78f33e18696e0a90f.jpg)
Joined: 09 Dec 2002 Posts: 2687 Location: Paris
|
Posted: Wed Mar 05, 2003 11:27 pm Post subject: |
|
|
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 |
|
![](templates/gentoo/images/spacer.gif) |
dioxmat Bodhisattva
![Bodhisattva Bodhisattva](/images/ranks/rank-bodhisattva.gif)
Joined: 04 May 2002 Posts: 709 Location: /home/mat
|
Posted: Thu Mar 06, 2003 2:34 pm Post subject: |
|
|
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 |
|
![](templates/gentoo/images/spacer.gif) |
DuF Advocate
![Advocate Advocate](/images/ranks/rank-G-1-advocate.gif)
![](images/avatars/500f78f33e18696e0a90f.jpg)
Joined: 09 Dec 2002 Posts: 2687 Location: Paris
|
Posted: Thu Mar 06, 2003 5:53 pm Post subject: |
|
|
y a une manière de faire un équivalent avec bash ? |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
Doudou Apprentice
![Apprentice Apprentice](/images/ranks/rank_rect_2.gif)
![](images/avatars/12978851293e75e9e8d6433.jpg)
Joined: 10 Jan 2003 Posts: 286 Location: Paris, France
|
Posted: Fri Mar 07, 2003 7:49 am Post subject: |
|
|
excellent l'options f de la commande ps, je ne connaissais pas non plus!! ![Very Happy :D](images/smiles/icon_biggrin.gif) |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
ghoti Advocate
![Advocate Advocate](/images/ranks/rank-G-1-advocate.gif)
![](images/avatars/15463172846237c094abba7.jpg)
Joined: 30 Dec 2002 Posts: 3636 Location: Belgium
|
Posted: Fri Mar 07, 2003 6:22 pm Post subject: |
|
|
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 |
|
![](templates/gentoo/images/spacer.gif) |
DuF Advocate
![Advocate Advocate](/images/ranks/rank-G-1-advocate.gif)
![](images/avatars/500f78f33e18696e0a90f.jpg)
Joined: 09 Dec 2002 Posts: 2687 Location: Paris
|
Posted: Sat Mar 08, 2003 4:54 am Post subject: |
|
|
effectivement ça marche bien, merci ghoti ! |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
|