bash script daemon

hi

I have the following script named ./daemonscript

while true
do
       #echo string to file results
	echo ok >> results
      #commands
	sleep 2
done


I call it the following way : ./daemonscript &

and I want it to stop when the user presses the "S" button together with the "Ctrl" button
How can I achieve that?

It's the first time I'm making something like that and I dont know even if I call it right because the file results doesnt show any message...:confused:

Once you daemonize it, you lose control of it. You'll have to control it some other way than keypresses. You could have some other program which sends a signal to the daemon process on control-s, perhaps.

Could you give me a simple example to understand what you mean exactly?
Is it better instead of running it as a daemon then to just run it with the while loop and stop it with the signal control-s?But in that case I would need an echo command and if the user doesn't press the control-s then it would wait instead of go on..

I can't really give you a simple example of something that can't work the way you want it to...

I have no idea what you'd need an echo for, or why it'd need to wait for anything.

The easiest thing to do would be to just loop, and wait for the user to do ctrl-C, sigint. Then you could just let that break the loop, or trap it and change some variable. If it must be ctrl-s, you could do finicky things with stty to redefine ctrl-s as ctrl-c for the same effect.

I think a better question might be why ctrl-s, and what's this daemon supposed to do.

corona is right - instead of showing how you decided to do it, pretend you are just telling us what you are trying to do, and have no clue how to accomplish your task.

Aside from the fact that what you wrote is not a true daemon. And. It still has a process group with a controlling terminal. Among other issues.