aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/testdata/testprog/gettid.go
blob: 1b3e29ab08e5f4012703093be408d6de53277954 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build linux

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
	"syscall"
)

func gettid() int {
	return syscall.Gettid()
}

func tidExists(tid int) (exists, supported bool) {
	stat, err := ioutil.ReadFile(fmt.Sprintf("/proc/self/task/%d/stat", tid))
	if os.IsNotExist(err) {
		return false, true
	}
	// Check if it's a zombie thread.
	state := bytes.Fields(stat)[2]
	return !(len(state) == 1 && state[0] == 'Z'), true
}