Last active
December 29, 2015 14:48
-
-
Save hyqhyq3/7686027 to your computer and use it in GitHub Desktop.
cgo daemon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"time" | |
) | |
/* | |
#include <unistd.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
//export my_daemon | |
extern void my_daemon() { | |
close(0); | |
close(1); | |
close(2); | |
if(fork() > 0) { | |
_exit(0); | |
} | |
setsid(); | |
} | |
*/ | |
import "C" | |
func main() { | |
C.my_daemon(); | |
// 下面的程序就运行在后台了 | |
for { | |
time.Sleep(time.Second) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment