From 82838bceaf4b90d3146869b8edf8826d0452e7c3 Mon Sep 17 00:00:00 2001 From: Prajwal S N Date: Tue, 1 Aug 2023 16:00:20 +0530 Subject: [PATCH] fix(crit): skip processes with no FDs Using `crit x fd` to list file descriptors now skips processes that have no associated FDs. Signed-off-by: Prajwal S N --- crit/explore.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crit/explore.go b/crit/explore.go index 3d2b98799..cd234e585 100644 --- a/crit/explore.go +++ b/crit/explore.go @@ -71,7 +71,7 @@ func (c *crit) ExplorePs() (*PsTree, error) { // Fd represents the file descriptors opened in a single process type Fd struct { PId uint32 `json:"pId"` - Files []*File `json:"files,omitempty"` + Files []*File `json:"files"` } // File represents a single opened file @@ -145,6 +145,11 @@ func (c *crit) ExploreFds() ([]*Fd, error) { Path: filePath, }) + // Omit if the process has no file descriptors + if len(fdEntry.Files) == 0 { + continue + } + fds = append(fds, &fdEntry) }