mirror of
				https://github.com/containers/podman.git
				synced 2025-10-31 10:00:01 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			42 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| // +build linux
 | |
| 
 | |
| package libpod
 | |
| 
 | |
| import (
 | |
| 	"strconv"
 | |
| 	"strings"
 | |
| 
 | |
| 	"github.com/containers/psgo"
 | |
| )
 | |
| 
 | |
| // GetContainerPidInformation returns process-related data of all processes in
 | |
| // the container.  The output data can be controlled via the `descriptors`
 | |
| // argument which expects format descriptors and supports all AIXformat
 | |
| // descriptors of ps (1) plus some additional ones to for instance inspect the
 | |
| // set of effective capabilities.  Eeach element in the returned string slice
 | |
| // is a tab-separated string.
 | |
| //
 | |
| // For more details, please refer to github.com/containers/psgo.
 | |
| func (c *Container) GetContainerPidInformation(descriptors []string) ([]string, error) {
 | |
| 	pid := strconv.Itoa(c.state.PID)
 | |
| 	// TODO: psgo returns a [][]string to give users the ability to apply
 | |
| 	//       filters on the data.  We need to change the API here and the
 | |
| 	//       varlink API to return a [][]string if we want to make use of
 | |
| 	//       filtering.
 | |
| 	psgoOutput, err := psgo.JoinNamespaceAndProcessInfo(pid, descriptors)
 | |
| 	if err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	res := []string{}
 | |
| 	for _, out := range psgoOutput {
 | |
| 		res = append(res, strings.Join(out, "\t"))
 | |
| 	}
 | |
| 	return res, nil
 | |
| }
 | |
| 
 | |
| // GetContainerPidInformationDescriptors returns a string slice of all supported
 | |
| // format descriptors of GetContainerPidInformation.
 | |
| func GetContainerPidInformationDescriptors() ([]string, error) {
 | |
| 	return psgo.ListDescriptors(), nil
 | |
| }
 | 
