Source file src/runtime/testdata/testprog/signal.go

     1  // Copyright 2015 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  //go:build !windows && !plan9
     6  // +build !windows,!plan9
     7  
     8  package main
     9  
    10  import (
    11  	"syscall"
    12  	"time"
    13  )
    14  
    15  func init() {
    16  	register("SignalExitStatus", SignalExitStatus)
    17  }
    18  
    19  func SignalExitStatus() {
    20  	syscall.Kill(syscall.Getpid(), syscall.SIGTERM)
    21  
    22  	// Should die immediately, but we've seen flakiness on various
    23  	// systems (see issue 14063). It's possible that the signal is
    24  	// being delivered to a different thread and we are returning
    25  	// and exiting before that thread runs again. Give the program
    26  	// a little while to die to make sure we pick up the signal
    27  	// before we return and exit the program. The time here
    28  	// shouldn't matter--we'll never really sleep this long.
    29  	time.Sleep(time.Second)
    30  }
    31  

View as plain text