LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Does anyone know of a daemon that in essence "does nothing"? (https://www.linuxquestions.org/questions/linux-software-2/does-anyone-know-of-a-daemon-that-in-essence-does-nothing-881413/)

kopatops 05-18-2011 09:59 AM

Does anyone know of a daemon that in essence "does nothing"?
 
I couldn't find it googling.

I think I want a daemon that does nothing but keep this bash script, (specified in the ~/.xinitrc exec line) alive:

(What I would like is written in bold)

Code:

LIBGL_ALWAYS_INDIRECT=1
INTEL_BATCH=1

#pcmanfm --desktop &
nautilus --no-default-window &
stalonetray &
#xfce4-panel &
python2 /usr/share/screenlets-manager/screenlets-daemon.py &
python2 /usr/share/screenlets/ACPIBattery/ACPIBatteryScreenlet.py &
pidgin &
compiz --use-root-window --indirect-rendering ccp &
daemon-that-uses-no-resources
#fluxbox

I used to have my X session die with the Compiz process, but now I need to execute some things after Compiz in the script above, meaning I have to background it.

I figure, anyhow, it makes sense to have the life of ~/.xinitrc depend on a process that isn't used for anything else (?).

business_kid 05-18-2011 10:06 AM

inetd with all services disabled :-))? There are options to inetd to allow it to use a command line specified config file.

segmentation_fault 05-18-2011 10:28 AM

Why don't you try to write a program or script that sleeps for eternity?

If I got it right, you want your xsession to die by another program, and not the compiz (I've never used compiz, so I'm not quit shure for what I say). Have you tried to add at the end of .xinitrc "exec xterm" ?
then the session will be terminated by closing that xterm (or any other program put there).

kopatops 05-18-2011 11:10 AM

(Pardon the delayed response)

Quote:

Originally Posted by segmentation_fault (Post 4359994)
Why don't you try to write a program or script that sleeps for eternity?

If I got it right, you want your xsession to die by another program, and not the compiz (I've never used compiz, so I'm not quit shure for what I say). Have you tried to add at the end of .xinitrc "exec xterm" ?
then the session will be terminated by closing that xterm (or any other program put there).

My exec line in .xinitrc (only 1 is allowed) invokes the script (~/bin/mo-de) in the original post, which serves as my desktop environment. This means that when mo-de ends, the xinitrc script ends, and my x-session ends.

Quote:

Originally Posted by segmentation_fault (Post 4359994)
Why don't you try to write a program or script that sleeps for eternity?

:) Exactly what I would like! But I don't know how to do this.

Code:

NAME
      sleep - delay for a specified amount of time

SYNOPSIS
      sleep NUMBER[SUFFIX]...
      sleep OPTION

DESCRIPTION
      Pause  for  NUMBER seconds.  SUFFIX may be `s' for seconds (the default), `m' for minutes,
      `h' for hours or `d' for days.  Unlike most implementations  that  require  NUMBER  be  an
      integer,  here  NUMBER may be an arbitrary floating point number.  Given two or more argu‐
      ments, pause for the amount of time specified by the sum of their values.

sleep doesn't accept "∞" as argument. :P

Quote:

Originally Posted by segmentation_fault (Post 4359994)
Have you tried to add at the end of .xinitrc "exec xterm" ?.

Indeed, I could replace daemon-that-uses-no-resources with xterm. But xterm would run as a window in my DE; I need a background process, something that doesn't get in my way "graphically". :)

EDIT: Maybe I was out of my mind writing "daemon"! That is probably not what I need. :doh:
I need something that stays attached to the script (~/bin/mo-de), keeping it alive.

Sorry for being difficult/ignorant :P
Thank you for the answers so far.

MTK358 05-18-2011 02:55 PM

Quote:

Originally Posted by kopatops (Post 4360034)
sleep doesn't accept "∞" as argument. :P

No problem:

Code:

while true; do sleep 60m; done
EDIT:

I found that the C standard library function "atof" (it converts text to a floating point number, and I would assume that this is what sleep uses) converts "inf" and "infinity" to an infinite value.

I tried this and it seems to work:

Code:

sleep inf

Nominal Animal 05-18-2011 03:47 PM

If you want to detach something from a script -- for example, from a startup script or a terminal --, use
Code:

( setsid command ... & ) </dev/null &>/dev/null
That command will run completely separately from the calling script and/or terminal. It will keep running even if you log out, for example.

For normal session commands, use
Code:

command ... &
command ... &
command ... &

wait

This way, when you exit, the process group will be sent a TERM signal, and all the commands will be terminated. The script will not exit normally unless all of the commands have exited.

kopatops 05-20-2011 05:06 PM

Quote:

Originally Posted by MTK358 (Post 4360243)
[...]
I found that the C standard library function "atof" (it converts text to a floating point number, and I would assume that this is what sleep uses) converts "inf" and "infinity" to an infinite value.

I tried this and it seems to work:

Code:

sleep inf

Yes, man - floating point it is. Thanks!:cool:
Should have tested this on my own :redface:. It does seem to work. I'll then just put sleep inf as the last line of my "DE" script and do a killall mo-de to end .xinitrc and thereby the x-session... Feel free to object if there is a more elegant/portable/obvious way to acheive what I want :)

Quote:

Originally Posted by Nominal Animal (Post 4360288)
If you want to detach something from a script -- for example, from a startup script or a terminal --, use
Code:

( setsid command ... & ) </dev/null &>/dev/null
That command will run completely separately from the calling script and/or terminal. It will keep running even if you log out, for example.

So, then

Code:

( setsid compiz ... & ) </dev/null &>/dev/null
will make compiz (my window manager) run in a new session, so parsing of the script can continue on to those extra lines I want in there. And still, the script won't end before the original command compiz has terminated, even though it is now "detached" from the script?

Am I way off? These process control techniques seem interesting, but I'm just learning about ps's, pgrp's, and session's, so I'm not sure I'll use this for some time. Just want to show my appreciation for the suggested solution; it doesn't seem to involve any extra software running at all, which is elegant.

Tnx all.

Nominal Animal 05-21-2011 11:33 AM

Quote:

Originally Posted by kopatops (Post 4362317)
So, then

Code:

( setsid compiz ... & ) </dev/null &>/dev/null
will make compiz (my window manager) run in a new session, so parsing of the script can continue on to those extra lines I want in there. And still, the script won't end before the original command compiz has terminated, even though it is now "detached" from the script?

Just the opposite: with the above, the script can exit without compiz getting killed. If I understood your situation correctly, that'd end your session.. so that's not what you want to do for compiz.

For compiz, you'll want to use
Code:

compiz ... &

# ... other commands to start in the background ...

wait

The single wait at the end makes the script wait for all of the commands started in the background -- compiz in this case -- to exit before the script ends. In other words, the script will sit in the wait command for as long as any of the backgrounded stuff is still running.

kopatops 05-21-2011 02:59 PM

Quote:

Originally Posted by Nominal Animal (Post 4362957)
Just the opposite: with the above, the script can exit without compiz getting killed. If I understood your situation correctly, that'd end your session.. so that's not what you want to do for compiz.

For compiz, you'll want to use
Code:

compiz ... &

# ... other commands to start in the background ...

wait

The single wait at the end makes the script wait for all of the commands started in the background -- compiz in this case -- to exit before the script ends. In other words, the script will sit in the wait command for as long as any of the backgrounded stuff is still running.

Oh, now I get it! :newbie:

This is exactly what I need. Just a single wait... Huge thank you Nominal Animal.

kopatops 05-22-2011 05:54 AM

For anyone who reads this thread; you might find the following information useful.
I found it by accident on the arch wiki .xinitrc page: https://wiki.archlinux.org/index.php/Xinitrc

Quote:

Originally Posted by Arch Wiki
Alternative method

If you need to start your window manager before launching additional applications, use the following method:

Code:

#!/bin/bash

openbox & wmpid=$!

urxvtd -q -f -o &
xscreensaver -no-splash &
fbpanel &

wait $wmpid

The first line runs openbox as a background process and immediately stores the process id ($!) in the variable wmpid. On the last line, the wait builtin is used to wait until the process specified by wmpid terminates.

Using this method, the X session will still end with the window manager, but you can start processes before/after it as you see fit. Hence, the assumption in my original post:

Quote:

Originally Posted by kopatops (Post 4359960)
I used to have my X session die with the Compiz process, but now I need to execute some things after Compiz in the script above, meaning I have to background it.

is not really true. Useful to note this fact :)
Thanks everyone. Won't touch the thread anymore by myself.


All times are GMT -5. The time now is 12:20 AM.