Sharing memory in IPFS commands

As a self-taught go developer I constantly refer to go-ipfs code to understand some of the good coding patterns.

I am working on something where I programatically start the ipfs node. I was trying to understand the shutdown code.

    Run: func(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment) error {

	nd, err := cmdenv.GetNode(env)
	if err != nil {
		return err

	if !nd.IsDaemon {
		return cmds.Errorf(cmds.ErrClient, "daemon not running")

	if err := nd.Close(); err != nil {
		log.Error("error while shutting down ipfs daemon:", err)

	return nil

The ipfs daemon is running in a separate process. How is this command able to stop the same running node? Is there some way this cmdenv is able to share memory between processes?

I might have to go much deeper in code to understand this, so if anyone knows it on the top of their head I would really appreciate it!

The go-ipfs commands library ( is network transparent. All commands defined on go-ipfs are exposed via the HTTP API.

When you run the ipfs command, it checks to see if a go-ipfs daemon is running and, if so, it sends the command to that daemon over the HTTP API. If the daemon, the ipfs command executes the command in-process, when possible.

Take a look at the makeExecutor function in cmd/ipfs/main.go for details on how go-ipfs actually constructs the command executor.


Sorry for getting back late. Went through the code and yes it makes sense now.