Run as a daemon or service: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Added Go)
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 156:
GP scripts cannot run in this fashion directly, but can be compiled into PARI code with <code>gp2c</code>. PARI code, whether from <code>gp2c</code> or not, can be run as a daemon just as [[#C|C]] would be.
 
=={{header|Perl 6PicoLisp}}==
<lang PicoLisp>(unless (fork)
(out "file.log"
(println *Pid) # First write the daemon's PID to the file
(for N 3600 # Write count for about one hour (if not killed)
(wait 1000)
(println N)
(flush) ) )
(bye) ) # Child terminates after one hour
 
(bye) # Parent terminates immediately</lang>
 
=={{header|Pike}}==
<code>__FILE__</code> is a preprocessor definition that contains the current filename.
if the first argument is "daemon" the program will be restarted with stdout redirected to "foo".
 
<lang Pike>int main(int argc, array argv)
if (sizeof(argv)>1 && argv[1] == "daemon")
{
Stdio.File newout = Stdio.File("foo", "wc");
Process.spawn_pike(({ __FILE__ }), ([ "stdout":newout ]));
return 1;
}
 
int i = 100;
while(i--)
{
write(i+"\n");
sleep(0.1);
}
}</lang>
 
=={{header|Racket}}==
<lang racket>
#lang racket
(require ffi/unsafe)
((get-ffi-obj 'daemon #f (_fun _int _int -> _int)) 0 0)
(with-output-to-file "/tmp/foo"
(λ() (for ([i 10]) (displayln (random 1000)) (flush-output) (sleep 1))))
</lang>
 
=={{header|PicoLispRaku}}==
(formerly Perl 6)
<lang perl6>#!/usr/bin/env perl6
 
Line 225 ⟶ 268:
1
</pre>
 
=={{header|PicoLisp}}==
<lang PicoLisp>(unless (fork)
(out "file.log"
(println *Pid) # First write the daemon's PID to the file
(for N 3600 # Write count for about one hour (if not killed)
(wait 1000)
(println N)
(flush) ) )
(bye) ) # Child terminates after one hour
 
(bye) # Parent terminates immediately</lang>
 
=={{header|Pike}}==
<code>__FILE__</code> is a preprocessor definition that contains the current filename.
if the first argument is "daemon" the program will be restarted with stdout redirected to "foo".
 
<lang Pike>int main(int argc, array argv)
if (sizeof(argv)>1 && argv[1] == "daemon")
{
Stdio.File newout = Stdio.File("foo", "wc");
Process.spawn_pike(({ __FILE__ }), ([ "stdout":newout ]));
return 1;
}
 
int i = 100;
while(i--)
{
write(i+"\n");
sleep(0.1);
}
}</lang>
 
=={{header|Racket}}==
<lang racket>
#lang racket
(require ffi/unsafe)
((get-ffi-obj 'daemon #f (_fun _int _int -> _int)) 0 0)
(with-output-to-file "/tmp/foo"
(λ() (for ([i 10]) (displayln (random 1000)) (flush-output) (sleep 1))))
</lang>
 
=={{header|Sidef}}==
10,333

edits