Launch without double-fork

Hi, I was checking why there is two procces every time than I launch a console. I found than spawn uses /bin/sh to lauch applications. I think than to expecific commands is no need to double-fork, I added the patch lo launch console without double-fork: diff -rN old-xmonad/XMonad/Config.hs new-xmonad/XMonad/Config.hs 183c183 < [ ((modMask .|. shiftMask, xK_Return), spawn $ XMonad.terminal conf) -- %! Launch terminal ---
[ ((modMask .|. shiftMask, xK_Return), spawnf $ XMonad.terminal conf) -- %! Launch terminal
diff -rN old-xmonad/XMonad/Core.hs new-xmonad/XMonad/Core.hs 30c30 < getAtom, spawn, spawnPID, getXMonadDir, recompile, trace, whenJust, whenX, ---
getAtom, spawn, spawnPID, spawnf, spawnPIDf, getXMonadDir, recompile, trace, whenJust, whenX,
406a407,424
-- | spawnf. Launch an external application. It forks the application and -- runs the 'String' using the PATH to locate -- runs the 'String' you pass as a command to /bin/sh. spawnf :: MonadIO m => String -> m () spawnf x = spawnPIDf x >> return ()
-- | Like 'spawnf', but returns the 'ProcessID' of the launched application spawnPIDf :: MonadIO m => String -> m ProcessID spawnPIDf x = io . forkProcess . finally nullStdin $ do uninstallSignalHandlers createSession executeFile x True [] Nothing where nullStdin = do fd <- openFd "/dev/null" ReadOnly Nothing defaultFileFlags dupTo fd stdInput closeFd fd
What do you think? -- LC, ("There is no Dana, only Zuul." - Cazafantasmas [1984])

Two questions:
- does this play well with configs that have arguments to the terminal
command? (e.g. urxvt -name foo)
- does this play well with zombification?
~d
Quoting Luis Cabellos
Hi, I was checking why there is two procces every time than I launch a console. I found than spawn uses /bin/sh to lauch applications. I think than to expecific commands is no need to double-fork,
I added the patch lo launch console without double-fork:
diff -rN old-xmonad/XMonad/Config.hs new-xmonad/XMonad/Config.hs 183c183 < [ ((modMask .|. shiftMask, xK_Return), spawn $ XMonad.terminal conf) -- %! Launch terminal ---
[ ((modMask .|. shiftMask, xK_Return), spawnf $ XMonad.terminal conf) -- %! Launch terminal
diff -rN old-xmonad/XMonad/Core.hs new-xmonad/XMonad/Core.hs 30c30 < getAtom, spawn, spawnPID, getXMonadDir, recompile, trace, whenJust, whenX, ---
getAtom, spawn, spawnPID, spawnf, spawnPIDf, getXMonadDir, recompile, trace, whenJust, whenX,
406a407,424
-- | spawnf. Launch an external application. It forks the application and -- runs the 'String' using the PATH to locate -- runs the 'String' you pass as a command to /bin/sh. spawnf :: MonadIO m => String -> m () spawnf x = spawnPIDf x >> return ()
-- | Like 'spawnf', but returns the 'ProcessID' of the launched application spawnPIDf :: MonadIO m => String -> m ProcessID spawnPIDf x = io . forkProcess . finally nullStdin $ do uninstallSignalHandlers createSession executeFile x True [] Nothing where nullStdin = do fd <- openFd "/dev/null" ReadOnly Nothing defaultFileFlags dupTo fd stdInput closeFd fd
What do you think?
--
LC, ("There is no Dana, only Zuul." - Cazafantasmas [1984]) _______________________________________________ xmonad mailing list xmonad@haskell.org http://www.haskell.org/mailman/listinfo/xmonad

On Tue, Dec 01, 2009 at 07:07:48PM +0100, Luis Cabellos wrote:
Hi, I was checking why there is two procces every time than I launch a console. I found than spawn uses /bin/sh to lauch applications. I think than to expecific commands is no need to double-fork,
I added the patch lo launch console without double-fork:
[elided]
What do you think?
spawnPIDf won't with applications that take arguments, for example: spawn "xset -b" I think the best solution is to add an 'exec' to your spawned applications: spawn "exec xterm" This is the shell's syntax to execute a program directly rather than fork. The current implementation seeks to balance all of these concerns: * users want to supply arguments to programs * users will find "spawn prog [arg1, arg2, arg3]" syntax unwieldy * we don't want to support a homebrewed argument tokenizer in xmonad * some users will want to use shell syntax in their spawns Cheers, Spencer Janssen

I notice than applications launched using dmenu doesn't have the double
fork. I changed the terminal=urxvt to terminal="exec urxvt" (as in dmenu
key binding) and also I don't have double-fork.
2190 2033 09:36 \_ /home/superman/.xmonad/xmonad-i386-linux
10259 2190 10:32 \_ /bin/sh -c urxvt
10260 10259 10:32 | \_ urxvt
10261 10260 10:32 | \_ bash
10286 10261 10:32 | \_ ssh sumerman@kriptongo.es
12482 2190 10:49 \_ urxvt
12493 12482 10:49 \_ bash
14711 12493 11:06 \_ ps -fea --forest
I'll worth to change spawn and automatically add exec to command string?
On Wed, Dec 2, 2009 at 4:36 AM, Spencer Janssen
On Tue, Dec 01, 2009 at 07:07:48PM +0100, Luis Cabellos wrote:
Hi, I was checking why there is two procces every time than I launch a console. I found than spawn uses /bin/sh to lauch applications. I think than to expecific commands is no need to double-fork,
I added the patch lo launch console without double-fork:
[elided]
What do you think?
spawnPIDf won't with applications that take arguments, for example:
spawn "xset -b"
I think the best solution is to add an 'exec' to your spawned applications:
spawn "exec xterm"
This is the shell's syntax to execute a program directly rather than fork.
The current implementation seeks to balance all of these concerns: * users want to supply arguments to programs * users will find "spawn prog [arg1, arg2, arg3]" syntax unwieldy * we don't want to support a homebrewed argument tokenizer in xmonad * some users will want to use shell syntax in their spawns
Cheers, Spencer Janssen _______________________________________________ xmonad mailing list xmonad@haskell.org http://www.haskell.org/mailman/listinfo/xmonad
-- LC, ("Prefiero caminar con una duda, que con un mal axioma." - Javier Krahe)

Hello, On Wed, Dec 02, 2009 at 11:38:42AM +0100, Luis Cabellos wrote:
I notice than applications launched using dmenu doesn't have the double fork. I changed the terminal=urxvt to terminal="exec urxvt" (as in dmenu key binding) and also I don't have double-fork.
I'd like to add that bash seems to automatically "exec" in cases it makes sense. When I type "bash -c urxvt", ps axf does not show "bash -c urxvt" anywhere, only urxvt. (in a lot of distributions nowadays, bash is not the shell behind /bin/sh, though) -- Tomáš Janoušek, a.k.a. Liskni_si, http://work.lisk.in/
participants (4)
-
Luis Cabellos
-
Spencer Janssen
-
Tomáš Janoušek
-
wagnerdm@seas.upenn.edu