Skip to content

os/exec: exec.Command("cat", "/proc/uptime") memory leak in golang 1.9 #27934

@yxdming

Description

@yxdming

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

1.9

What operating system and processor architecture are you using (go env)?

SuSE

What did you do?

When i use exec.Command("cat", "/proc/uptime") in my programe, i found that there is a memory leak in this call. The memory used by program goes high after 2 hours from initial 20MB to 105MB and increasing continuously unless i restart the programe. The code as below.

func GetSecondFromSystemStart() int {
	out, err := exec.Command("cat", "/proc/uptime").Output()
	if(err != nil){
		logger.ErrorLog(MODULE_NAME, "get time from start fail:%s", err.Error())
	}else{
		vTimeString := strings.Split(string(out), ".")
		if(len(vTimeString) == 0){
			logger.ErrorLog(MODULE_NAME, "get time from start fail")
		}else{
			sed, e := strconv.Atoi(vTimeString[0])
			if(e != nil){
				logger.ErrorLog(MODULE_NAME, "get time from start fail:%s", e.Error())
			}else{
				logger.DebugLog(MODULE_NAME, "get time from start:%d", sed)
				return sed
			}
		}
	}
	return 0
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions