- Put
cinterface.go
,cinterface.c
andtest.h
in~/go/src/cinterface/
- Then call
go build -buildmode=c-archive cinterface
, this will producecinterface.a
andcinterface.h
in current directory - Put
main.c
andtest.h
in current directory and callgcc -o main -I. cinterface.a main.c
, this will produce final binary
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 ( | |
"os/exec" | |
"os" | |
"time" | |
) | |
func init() { | |
isForked := os.Getenv("DAEMON") |
This is an example. To run it simply do go build -o slave slave.go && go build -o main main.go && ./main
Then you can try typing say
for slave process to produce output or exit
for slave process to exit.
There is an issue when slave exits main process still alive and starts burning through CPU cycles.
But I am lazy to fix that, feel free to do that.
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
/* | |
* Copyright 2014 - Alexey Kamenskiy | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software |