github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/cmds/core/kill/signaler_unix.go (about)

     1  // Copyright 2016-2017 the u-root 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 !plan9
     6  // +build !plan9
     7  
     8  package main
     9  
    10  import (
    11  	"fmt"
    12  	"os"
    13  	"strconv"
    14  	"syscall"
    15  )
    16  
    17  var defaultSignal = "-SIGTERM"
    18  
    19  func kill(sig os.Signal, pids ...string) []error {
    20  	var errs []error
    21  	s := sig.(syscall.Signal)
    22  	for _, p := range pids {
    23  		pid, err := strconv.Atoi(p)
    24  		if err != nil {
    25  			errs = append(errs, fmt.Errorf("%v: arguments must be process or job IDS", p))
    26  			continue
    27  		}
    28  		if err := syscall.Kill(pid, s); err != nil {
    29  			errs = append(errs, err)
    30  		}
    31  
    32  	}
    33  	return errs
    34  }