You are not logged in.

#1 2010-08-11 13:06:56

valvet
Member
From: Denmark
Registered: 2009-06-06
Posts: 147

[SOLVED] Launching sh scripts (dzen2 bar) from xinitrc, multiple proc

Hi

I launch some SH from .xinitrc, but they appear multiple times and I cannot figure out why.

This is how I do, from .xinitrc - running xmonad:

# start dzen2 scripts
./dev/dzen2/scripts/rtop.sh &
./dev/dzen2/scripts/rbottom.sh &
./dev/dzen2/scripts/lbottom.sh &

When I look in the process list (ps aux | grep sh) I get this result:

michael   7184  0.0  0.0      0     0 tty1     Z    11:19   0:00 [sh] <defunct>
michael   7186  0.0  0.0   6060  1360 tty1     S    11:19   0:00 /bin/bash ./dev/dzen2/scripts/rtop.sh
michael   7187  0.0  0.0   6060  1324 tty1     S    11:19   0:00 /bin/bash ./dev/dzen2/scripts/rbottom.sh
michael   7188  0.0  0.0   6060  1320 tty1     S    11:19   0:00 /bin/bash ./dev/dzen2/scripts/lbottom.sh
michael   7190  0.0  0.0   6064   788 tty1     S    11:19   0:00 /bin/bash ./dev/dzen2/scripts/rbottom.sh
michael   7199  0.2  0.0   6320  1104 tty1     S    11:19   0:34 /bin/bash ./dev/dzen2/scripts/rtop.sh
michael   7480  0.0  0.0   6064   840 tty1     S    11:19   0:00 /bin/bash ./dev/dzen2/scripts/lbottom.sh

Example script:

source "/home/michael/dev/dzen2/scripts/settings.sh"

while :
do
    echo -e "  ^fg($MYCOLORBLUE)^i($ICONPATH/shroom.xbm)^fg($MYCOLORWHITE)  $(uname -r | tr '[A-Z]' ['a-z'])"
    sleep 300 
done | /usr/bin/dzen2 -ta l -h 20 -w 900 -y 800 -fg '#c4c4c4' -fn "$FONT"

Any ideas as to why they're launched twice?

Thanks!

Last edited by valvet (2010-11-08 14:50:47)

Offline

#2 2010-08-11 13:27:18

mikesd
Member
From: Australia
Registered: 2008-02-01
Posts: 788
Website

Re: [SOLVED] Launching sh scripts (dzen2 bar) from xinitrc, multiple proc

Any chance your .xinitrc is being sourced twice? What does your .xinitrc look like? How are you starting X?

Offline

#3 2010-08-11 13:33:24

valvet
Member
From: Denmark
Registered: 2009-06-06
Posts: 147

Re: [SOLVED] Launching sh scripts (dzen2 bar) from xinitrc, multiple proc

Hey, thanks for responding.

I run X automatically, when logging in at tty1, like so:

# startx when logging into tty1
if [[ -z "$DISPLAY" ]] && [[ $(tty) = /dev/tty1 ]]; then
    . startx
    logout
fi

My .xinit looks like this:

michael@princess ~> cat .xinitrc 
# start terminal emulation daemon
urxvtd -q -o -f &

# [url]http://wiki.archlinux.org/index.php/Per_Application_Transparency[/url]
#xcompmgr &
#devilspie -a &

# set keyboard language, and enable restart X
setxkbmap dk -option terminate:ctrl_alt_bksp &

# set the cursor
xsetroot -cursor_name left_ptr

# set wallpaper
sh /home/michael/.fehbg &

# hide mouse when not needed
unclutter -idle 1 &

# start dzen2 scripts
./dev/dzen2/scripts/rtop.sh &
./dev/dzen2/scripts/rbottom.sh &
./dev/dzen2/scripts/lbottom.sh &

# start xmonad
exec ck-launch-session dbus-launch --exit-with-session xmonad

I don't know when .xinit is sourced, but I imagine it happens when X is started, using startx? I've not sourced it manually anywhere.

- m

Offline

#4 2010-08-11 22:29:30

mikesd
Member
From: Australia
Registered: 2008-02-01
Posts: 788
Website

Re: [SOLVED] Launching sh scripts (dzen2 bar) from xinitrc, multiple proc

Weird. Can't see any issues with that. Perhaps you could add a line to your .xinitrc such as:

echo "XXX" >> /home/michael/dummy

and see if it is in fact being sourced twice.

Perhaps the duplicates are from a previous login? Do they get killed when you logout? Do they still appear after a reboot and login?

Offline

#5 2010-08-11 22:32:10

valvet
Member
From: Denmark
Registered: 2009-06-06
Posts: 147

Re: [SOLVED] Launching sh scripts (dzen2 bar) from xinitrc, multiple proc

mikesd wrote:

Weird. Can't see any issues with that. Perhaps you could add a line to your .xinitrc such as:

echo "XXX" >> /home/michael/dummy

and see if it is in fact being sourced twice.

Perhaps the duplicates are from a previous login? Do they get killed when you logout? Do they still appear after a reboot and login?

That's a good test, I'll try that :-)

Offline

#6 2010-08-11 22:52:20

valvet
Member
From: Denmark
Registered: 2009-06-06
Posts: 147

Re: [SOLVED] Launching sh scripts (dzen2 bar) from xinitrc, multiple proc

I did what you said, and echo'ed some stuff in .xinitrc - it only gets echoed once :-(.. this is weird. Can it have something to do with the loops inside my scripts? See example script I posted earlier.

Once I logout (using ctrl+alt+del), no bash processes exists, so the scripts are closed - they get doubled once I login to X.

Thanks for helping :-)

- m

Offline

#7 2010-08-12 00:39:19

Knute
Member
From: Minot, ND
Registered: 2009-03-17
Posts: 604

Re: [SOLVED] Launching sh scripts (dzen2 bar) from xinitrc, multiple proc

What does your /home/michael/dev/dzen2/scripts/settings.sh look like?


Knute

Offline

#8 2010-08-12 08:47:04

valvet
Member
From: Denmark
Registered: 2009-06-06
Posts: 147

Re: [SOLVED] Launching sh scripts (dzen2 bar) from xinitrc, multiple proc

Hi Knute

Well, it looks like this:

#!/bin/bash
# vim:ft=bash ts=4
#

FONT='xft:Droid Sans Mono:style=Regular:pixelsize=11:antialias=true:hinting=true:hintstyle=hintfull'
ICONPATH='/usr/share/icons/sm4tik'

MYCOLORBLACK='#000000'
MYCOLORWHITE='#ffffff'
MYCOLORBLUE='#d5767e'
MYCOLORGRAY='#484848'
MYCOLORGRAYDARK='#b8bcb8'
MYCOLORGRAYALT='#c4c4c4'
MYCOLORRED='#ff6565'

But this also happened when I diden't have a settings file :x

Offline

#9 2010-08-12 09:29:41

knopwob
Member
From: Hannover, Germany
Registered: 2010-01-30
Posts: 239
Website

Re: [SOLVED] Launching sh scripts (dzen2 bar) from xinitrc, multiple proc

maybe you can get some hints by looking at the parent ids of your scripts, to see what process started them

Offline

#10 2010-08-12 10:38:09

valvet
Member
From: Denmark
Registered: 2009-06-06
Posts: 147

Re: [SOLVED] Launching sh scripts (dzen2 bar) from xinitrc, multiple proc

knopwob wrote:

maybe you can get some hints by looking at the parent ids of your scripts, to see what process started them

It looks like this:

http://omploader.org/vNTd3Zg

As I can make out, it seems that lbottom.sh is launching another lbottom.sh? Before dzen.

Thanks :-)

- m

Offline

#11 2010-08-12 11:28:14

mikesd
Member
From: Australia
Registered: 2008-02-01
Posts: 788
Website

Re: [SOLVED] Launching sh scripts (dzen2 bar) from xinitrc, multiple proc

Hmmm. It is the script itself. I get the same outcome, two instances of the script, with:

#!/bin/bash

while :
do
    echo "XXX"
    sleep 300
done | dzen2 

I'm guessing it is something to do with subshells though I'm not exactly sure what. smile

Offline

#12 2010-08-12 11:34:05

valvet
Member
From: Denmark
Registered: 2009-06-06
Posts: 147

Re: [SOLVED] Launching sh scripts (dzen2 bar) from xinitrc, multiple proc

mikesd wrote:

Hmmm. It is the script itself. I get the same outcome, two instances of the script, with:

#!/bin/bash

while :
do
    echo "XXX"
    sleep 300
done | dzen2 

I'm guessing it is something to do with subshells though I'm not exactly sure what. smile

Interesting :-).. it doesn't really bother me, but I just assume it's using double the resources. My rtop script for example is sleeping every 1 sec (has time/date printing out), if two of those are running at the same time, that's not ideal :x.

Well, hopefully someone can figure out why, based on your findings above :-)

Thanks!

- m

Offline

#13 2010-08-13 09:20:23

valvet
Member
From: Denmark
Registered: 2009-06-06
Posts: 147

Re: [SOLVED] Launching sh scripts (dzen2 bar) from xinitrc, multiple proc

Hi again.

I should mention that this also happens when the scripts are zsh instead of sh. Odd!

Offline

#14 2010-08-13 09:53:55

knopwob
Member
From: Hannover, Germany
Registered: 2010-01-30
Posts: 239
Website

Re: [SOLVED] Launching sh scripts (dzen2 bar) from xinitrc, multiple proc

hey,

i just did some reading and figured out, that both sites of a pipe are executed in their own subshell. So the second process with the same name is basically just the subshell executing the while-loop. So nothing to worry ;-)

Last edited by knopwob (2010-08-13 09:54:27)

Offline

#15 2010-08-13 10:32:26

mikesd
Member
From: Australia
Registered: 2008-02-01
Posts: 788
Website

Re: [SOLVED] Launching sh scripts (dzen2 bar) from xinitrc, multiple proc

Ah. Was this "reading" in the BASH man page?

Offline

#16 2010-08-13 11:20:14

knopwob
Member
From: Hannover, Germany
Registered: 2010-01-30
Posts: 239
Website

Re: [SOLVED] Launching sh scripts (dzen2 bar) from xinitrc, multiple proc

mikesd wrote:

Ah. Was this "reading" in the BASH man page?

nope, a book about shell programming lying next to me.

Offline

#17 2010-08-13 21:50:13

valvet
Member
From: Denmark
Registered: 2009-06-06
Posts: 147

Re: [SOLVED] Launching sh scripts (dzen2 bar) from xinitrc, multiple proc

knopwob wrote:

hey,

i just did some reading and figured out, that both sites of a pipe are executed in their own subshell. So the second process with the same name is basically just the subshell executing the while-loop. So nothing to worry ;-)

Ah excellent, knopwob. Thank you for your help, and everyone else also :-).

Love this community.

- m

Offline

#18 2010-08-14 02:37:22

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: [SOLVED] Launching sh scripts (dzen2 bar) from xinitrc, multiple proc

valvet wrote:

Love this community.

Then please give some back and mark the thread as solved: it will make it easier for others to find the solution in future...
http://wiki.archlinux.org/index.php/For … ow_to_Post


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#19 2010-08-17 16:56:39

milomouse
Member
Registered: 2009-03-24
Posts: 940
Website

Re: [SOLVED] Launching sh scripts (dzen2 bar) from xinitrc, multiple proc

good to hear you fixed the problem. as a side note, there's also "XMonad.Util.SpawnOnce" in xmonad-contrib-darcs that may do what you want. it's what i use for my external dzen scripts (i used to start them from .xinitrc before i found this).

Offline

Board footer

Powered by FluxBB