Skip to content

Instantly share code, notes, and snippets.

@hyqhyq3
Last active December 29, 2015 14:48
Show Gist options
  • Save hyqhyq3/7686027 to your computer and use it in GitHub Desktop.
Save hyqhyq3/7686027 to your computer and use it in GitHub Desktop.
cgo daemon
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