Home | History | Annotate | Download | only in testprog
      1 // Copyright 2017 The Go Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style
      3 // license that can be found in the LICENSE file.
      4 
      5 // +build linux
      6 
      7 package main
      8 
      9 import (
     10 	"bytes"
     11 	"fmt"
     12 	"io/ioutil"
     13 	"os"
     14 	"syscall"
     15 )
     16 
     17 func gettid() int {
     18 	return syscall.Gettid()
     19 }
     20 
     21 func tidExists(tid int) (exists, supported bool) {
     22 	stat, err := ioutil.ReadFile(fmt.Sprintf("/proc/self/task/%d/stat", tid))
     23 	if os.IsNotExist(err) {
     24 		return false, true
     25 	}
     26 	// Check if it's a zombie thread.
     27 	state := bytes.Fields(stat)[2]
     28 	return !(len(state) == 1 && state[0] == 'Z'), true
     29 }
     30