小编Anf*_*nee的帖子

Golang:Child Processes成为Zombies

我在Go中有一个应用程序重新路由二进制文件的STDIN和STDOUT,然后运行它们.简而言之,我正在做:

- create command object with the binary path (lets call the object command A) - create command object with the binary path (calling it command B) - set the stdout of command B to the stdin of Command A - start command A - start command B

我注意到,当命令A运行时,只要命令B的进程退出,它就会变成进程表中的僵尸进程.

这是一个例子:

commandA := exec.Command("samplebin")
commandB := exec.Command("sample2bin")

cmdAStdin := commandA.StdinPipe()

commandB.Stdout = cmdAStdin

commandA.Start()
commandB.Start()
Run Code Online (Sandbox Code Playgroud)

如果commandB仍在运行时,为什么commandB会退出僵尸?我在Ubuntu 14上运行Go 1.5.

stdin stdout process go zombie-process

8
推荐指数
1
解决办法
3825
查看次数

为什么不读取/写入其内容的结构的方法仍会导致竞争情况?

戴夫·切尼博客,下面的代码显然会导致比赛的情况下仅通过改变来解决func (RPC) version() intfunc (*RPC) version() int:

package main

import (
        "fmt"
        "time"
)

type RPC struct {
        result int
        done   chan struct{}
}

func (rpc *RPC) compute() {
        time.Sleep(time.Second) // strenuous computation intensifies
        rpc.result = 42
        close(rpc.done)
}

func (RPC) version() int {
        return 1 // never going to need to change this
}

func main() {
        rpc := &RPC{done: make(chan struct{})}

        go rpc.compute()         // kick off computation in the background
        version := …
Run Code Online (Sandbox Code Playgroud)

concurrency struct go race-condition goroutine

5
推荐指数
1
解决办法
77
查看次数

为什么我要担心CPython中的线程安全?

据我所知,Global Interpreter Lock只允许一个线程访问解释器并执行字节码.如果是这种情况,那么在任何给定时间,只有一个线程将使用解释器及其内存.

有了这个,我认为排除有种族案例的可能性是公平的,因为没有两个线程可以同时访问解释器的内存,但我仍然看到关于确保数据结构是"线程安全"的警告.它有可能覆盖python解释器的所有实现(如cython),它可以关闭GIL并允许真正的多线程.

我理解线程安全在没有启用GIL的解释器环境中的重要性.但是,对于CPython,为什么在编写多线程python代码时会鼓励线程安全?在CPython环境中可能发生的更糟糕的是什么?

python multithreading cpython thread-safety gil

5
推荐指数
1
解决办法
604
查看次数

为什么不能免费()工作?

每当我将输入存储在char*中的已分配空间之上时,我就会收到free()错误.继承人错误:

*** Error in ./input': free(): invalid next size (fast): 0x09713008 ***

当我删除free()时,程序运行完美,即使我输入的分配大小超过了分配的大小.为什么会这样?我该怎样预防呢?这是我的代码供参考:

int main(void){

  float x; // used to store the float the user entered.
  char c; // character used to check if the user entered a character after the float
  int loop=0;

  char * usr_input = malloc(50); //allocates memory to store the string from the stdin

  // loops until the user enters a float and only a float
  do{
    //gets the input string from stdin
    scanf("%s",usr_input);

    if(usr_input==NULL)
        printf("You've …
Run Code Online (Sandbox Code Playgroud)

c malloc free core abort

2
推荐指数
1
解决办法
123
查看次数