Hallo, ich möchte gerne ein Programm schreiben, welches im Hintergrund auf eine bestimmte Aktion wartet und daraufhin aktiv wird (nennt sich AFAIK Deamon). Nur: Wie genau programmiert man so etwas unter Linux? Ich brauchte für meine Progz bisher immer einen Ausgabepunkt (z.B. tty0). Wie genau definiert sich ein Deamon? Was zeichnet ein solches Programm aus? Danke! Ciao Julian ____________________________________ ______ JP solution Internet Services / \ D-31655 Stadthagen, Germany /___/ / / Visit: www.JP-solution.de \__/ solution --------------------------------------------------------------------- To unsubscribe, e-mail: suse-linux-unsubscribe@suse.com For additional commands, e-mail: suse-linux-help@suse.com
* Julian Pawlowski schrieb am 12.Okt.2000:
ich möchte gerne ein Programm schreiben, welches im Hintergrund auf eine bestimmte Aktion wartet und daraufhin aktiv wird (nennt sich AFAIK Deamon). Nur: Wie genau programmiert man so etwas unter Linux? Ich brauchte für meine Progz bisher immer einen Ausgabepunkt (z.B. tty0). Wie genau definiert sich ein Deamon? Was zeichnet ein solches Programm aus?
Wenn überhaupt, dann daß sie keinem Terminal zugeordnet sind. Das erreicht man am besten, indem sie direkt oder indirekt von init gestartet werden. Zum Beispiel über einem startskrip in /sbin/init.d oder in /sbin/init.d/boot.local Bernd -- Bitte die Etikette dieser Liste beachten: http://www.ndh.net/home/schult/ Bitte Realnamen angeben, kein Vollquoting, kein Html, PGP oder Visitenkarten benutzen. Signatur mit "-- " abtrennen, bei Antworten "Re: " voranstellen, sonst nichts. |Zufallssignatur 4 --------------------------------------------------------------------- To unsubscribe, e-mail: suse-linux-unsubscribe@suse.com For additional commands, e-mail: suse-linux-help@suse.com
Hallo! Bernd Brodesser schrieb:
* Julian Pawlowski schrieb am 12.Okt.2000:
ich möchte gerne ein Programm schreiben, welches im Hintergrund auf eine bestimmte Aktion wartet und daraufhin aktiv wird (nennt sich AFAIK Deamon). Nur: Wie genau programmiert man so etwas unter Linux? Ich brauchte für meine Progz bisher immer einen Ausgabepunkt (z.B. tty0). Wie genau definiert sich ein Deamon? Was zeichnet ein solches Programm aus?
Wenn überhaupt, dann daß sie keinem Terminal zugeordnet sind. Das erreicht man am besten, indem sie direkt oder indirekt von init gestartet werden. Zum Beispiel über einem startskrip in /sbin/init.d oder in /sbin/init.d/boot.local
Ich stehe beim Umstieg auf C leider auch noch am Anfang. Allerdings habe ich schon ein bischen über Daemons gelernt. Der normale Weg ein Programm in den Hintergrund zu befördern ist wohl die Standardein- und Ausgabestreams zu schließen. Um mit dem Programm kommunizieren zu können werden sog. Sockets benutzt. Sockets sind Datenverbindungen zwischen Programmen auf dem selben oder per Netzwerk erreichbaren Rechnern. Es handelt sich dabei AFAIK nicht um "normale" TCP/IP-Verbindungen. An weiteren Infos (insbesondere Tutorials o.ä.) bin ich immer interessiert. Gruß, Till. --------------------------------------------------------------------- To unsubscribe, e-mail: suse-linux-unsubscribe@suse.com For additional commands, e-mail: suse-linux-help@suse.com
* Till Wollenberg schrieb am 13.Okt.2000:
Bernd Brodesser schrieb:
* Julian Pawlowski schrieb am 12.Okt.2000:
ich möchte gerne ein Programm schreiben, welches im Hintergrund auf eine bestimmte Aktion wartet und daraufhin aktiv wird (nennt sich AFAIK Deamon). Nur: Wie genau programmiert man so etwas unter Linux? Ich brauchte für meine Progz bisher immer einen Ausgabepunkt (z.B. tty0). Wie genau definiert sich ein Deamon? Was zeichnet ein solches Programm aus?
Wenn überhaupt, dann daß sie keinem Terminal zugeordnet sind. Das erreicht man am besten, indem sie direkt oder indirekt von init gestartet werden. Zum Beispiel über einem startskrip in /sbin/init.d oder in /sbin/init.d/boot.local
Ich stehe beim Umstieg auf C leider auch noch am Anfang. Allerdings habe ich schon ein bischen über Daemons gelernt. Der normale Weg ein Programm in den Hintergrund zu befördern ist wohl die Standardein- und Ausgabestreams zu schließen.
Ja, aber das machst Du aber bitte nicht selber mit dem Programm, das macht die bash. Solange Du keine shell selber programmieren willst, laß lieber die Finger davon.
Um mit dem Programm kommunizieren zu können werden sog. Sockets benutzt. Sockets sind Datenverbindungen zwischen Programmen auf dem selben oder per Netzwerk erreichbaren Rechnern. Es handelt sich dabei AFAIK nicht um "normale" TCP/IP-Verbindungen.
Wie Du richtig schreibst werden Sockets für TCP/IP benutzt. Die normale Komunikation zwichen Programme werden mit pipes gemacht. Die legst Du mit dem Systemaufruf pipe () an. Siehe hierzu man 2 pipe. Bernd -- ROTFL = Rolling On The Floor, Laughing = Auf dem Boden wälzen, lachend. SCNR = Sorry, Could Not Resist = Sorry, Ich konte nicht wiederstehen. AFAIK = As Far As I Know = So weit ich weis|BTW = By The Way = Nebenbei bemerkt IMHO = In My Humble Opinion = meiner bescheidenen Meinung nach |Zufallssig. 9 --------------------------------------------------------------------- To unsubscribe, e-mail: suse-linux-unsubscribe@suse.com For additional commands, e-mail: suse-linux-help@suse.com
Hallo!
* Till Wollenberg schrieb am 13.Okt.2000:
Bernd Brodesser schrieb:
Wenn überhaupt, dann daß sie keinem Terminal zugeordnet sind. Das erreicht man am besten, indem sie direkt oder indirekt von init gestartet werden. Zum Beispiel über einem startskrip in /sbin/init.d oder in /sbin/init.d/boot.local
Ich stehe beim Umstieg auf C leider auch noch am Anfang. Allerdings habe ich schon ein bischen über Daemons gelernt. Der normale Weg ein Programm in den Hintergrund zu befördern ist wohl die Standardein- und Ausgabestreams zu schließen.
Ja, aber das machst Du aber bitte nicht selber mit dem Programm, das macht die bash. Solange Du keine shell selber programmieren willst, laß lieber die Finger davon.
Wieso macht das nur die Shell? Ich kann zwar jedes Programm mit angehängtem & starten, um es in den Hintergrund zu befördern, aber einige Programme (squid, imwheel etc.) starten von sich aus im Hintergrund. Wie machen die das denn?
Um mit dem Programm kommunizieren zu können werden sog. Sockets benutzt. Sockets sind Datenverbindungen zwischen Programmen auf dem selben oder per Netzwerk erreichbaren Rechnern. Es handelt sich dabei AFAIK nicht um "normale" TCP/IP-Verbindungen.
Wie Du richtig schreibst werden Sockets für TCP/IP benutzt. Die normale Komunikation zwichen Programme werden mit pipes gemacht. Die legst Du mit dem Systemaufruf pipe () an. Siehe hierzu man 2 pipe.
Das ist alles noch ziemlich komplex. Ich werde mich in der nächsten Zeit damit auseinandersetzen (müssen). Ich hoffe, die Liste kann mir bei nicht allzu "dummen" Fragen helfen. ;-) Gruß, Till. --------------------------------------------------------------------- To unsubscribe, e-mail: suse-linux-unsubscribe@suse.com For additional commands, e-mail: suse-linux-help@suse.com
* Till Wollenberg schrieb am 17.Okt.2000:
* Till Wollenberg schrieb am 13.Okt.2000:
Bernd Brodesser schrieb:
Wenn überhaupt, dann daß sie keinem Terminal zugeordnet sind. Das erreicht man am besten, indem sie direkt oder indirekt von init gestartet werden. Zum Beispiel über einem startskrip in /sbin/init.d oder in /sbin/init.d/boot.local
Ich stehe beim Umstieg auf C leider auch noch am Anfang. Allerdings habe ich schon ein bischen über Daemons gelernt. Der normale Weg ein Programm in den Hintergrund zu befördern ist wohl die Standardein- und Ausgabestreams zu schließen.
Ja, aber das machst Du aber bitte nicht selber mit dem Programm, das macht die bash. Solange Du keine shell selber programmieren willst, laß lieber die Finger davon.
Wieso macht das nur die Shell? Ich kann zwar jedes Programm mit angehängtem & starten, um es in den Hintergrund zu befördern, aber einige Programme (squid, imwheel etc.) starten von sich aus im Hintergrund. Wie machen die das denn?
Mag sein, aber das sind doch nicht die Programme, die Du selber schreibst. Es ist schon besser, wenn die Standardein- und -ausgabe nicht umgelenkt werden. Sonst verhält sich Dein Programm nicht wie jedes andere. Bernd -- Umsteiger von Microsoft Windows xx? Hast Du schon file://usr/doc/howto/de/DE-DOS-nach-Linux-HOWTO.txt gelesen? Auch file://usr/doc/Books/Linuxhandbuch.dvi ist zu empfehlen. |Zufallssignatur 1 --------------------------------------------------------------------- To unsubscribe, e-mail: suse-linux-unsubscribe@suse.com For additional commands, e-mail: suse-linux-help@suse.com
Hi Till On Tue, Oct 17, 2000 at 04:38:50PM +0200, Till Wollenberg wrote:
Wieso macht das nur die Shell? Ich kann zwar jedes Programm mit angehängtem & starten, um es in den Hintergrund zu befördern, aber einige Programme (squid, imwheel etc.) starten von sich aus im Hintergrund. Wie machen die das denn?
Die meldeen sich vom sog. steuernden Terminal ab. wie das genau geht willst du eigentlich bei Richard Stevens 'Programmieren in der Unix Umgebung' und 'Programmierung von Unix Netzwerken' nachlesen. Das sind _die_ Standardwerke dafür. Die isbns kann ich dir evtl. am Freitag raussuchen, erinner mich bitte nochmal dran per PM.
Das ist alles noch ziemlich komplex. Ich werde mich in der nächsten Zeit damit auseinandersetzen (müssen). Ich hoffe, die Liste kann mir bei nicht allzu "dummen" Fragen helfen. ;-)
ohne hier jemandem zu nahe treten zu wollen bist du damit nicht unbedingt beim richtigen Forum dafür. MfG. Falk --------------------------------------------------------------------- To unsubscribe, e-mail: suse-linux-unsubscribe@suse.com For additional commands, e-mail: suse-linux-help@suse.com
Hallo Falk, * Am 17.10.2000 um 19:00 Uhr schrieb Falk Sauer:
Die meldeen sich vom sog. steuernden Terminal ab. wie das genau geht willst du eigentlich bei Richard Stevens 'Programmieren in der Unix Umgebung' und 'Programmierung von Unix Netzwerken' nachlesen. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
<Schleichwerbung> Dieses nette Büchlein gab es vor kurzem bei http://www.smm.de für sage und schreibe 18,95DM. (Bestellnummer: 11868-233) </Schleichwerbung> SCNR Jür"der-sich-gleich-eins-geordert-hat"gen -- Die letzten Worte eines Kantinenkoches: "Merkwürdig ruhig da draussen..." / Registered Linux-User #130804 http://counter.li.org \ \ Linux Stammtisch Bremerhaven http://linux.hs-bremerhaven.de / --------------------------------------------------------------------- To unsubscribe, e-mail: suse-linux-unsubscribe@suse.com For additional commands, e-mail: suse-linux-help@suse.com
* Till Wollenberg wrote on Tue, Oct 17, 2000 at 16:38 +0200:
Wieso macht das nur die Shell? Ich kann zwar jedes Programm mit angehängtem & starten, um es in den Hintergrund zu befördern, aber einige Programme (squid, imwheel etc.) starten von sich aus im Hintergrund. Wie machen die das denn?
man 2 fork man 2 setsid Daemon werden, Kurzform: - forken, damit setsid sicher klappt - dad kann exit() machen - Child: evtl. priviligierte Aktionen machen - evtl. root permissions droppen - dann close() auf alles (mit getrlimit Anzahl der erlaubten fd holen, dann alle in einer for Schleife schließen, evtl. stderr + stdout in logfile umleiten, oder syslog verwenden - setsid rufen (kein controlling terminal mehr, neue process group, setsid caller ist session leader/group leader) - jetzt läuft ne neue process group mit dem process als group leader (session leader) - wenn Du jetzt fork()st, gehören alle Childs auch zu der process group - die process group id == session id == pid vom setsid-caller - beim killen ruft der leader kill(0, SIG_TERM) oder so auf, und beendet damit die gesammte process group (muß natürlich selbst dieses ignorieren, oder kill(-1, SIG_TERM), welches den "ersten" nicht mit "trifft", man 2 kill oki, Steffen -- Dieses Schreiben wurde maschinell erstellt, es trägt daher weder Unterschrift noch Siegel. --------------------------------------------------------------------- To unsubscribe, e-mail: suse-linux-unsubscribe@suse.com For additional commands, e-mail: suse-linux-help@suse.com
participants (6)
-
B.Brodesser@online-club.de
-
falk@hb-fein.de
-
info@jp-solution.de
-
Juergen_Schwarting@gmx.de
-
steffen@dett.de
-
wollenberg@arcormail.de