From 794e7b43599b4ecb3786de401725ba99087a501e Mon Sep 17 00:00:00 2001 From: Lucas Hoffmann Date: Wed, 15 Aug 2018 12:39:10 +0200 Subject: [PATCH 1/2] API: Use `ps -o comm` in nvim_get_proc() - The POSIX version of ps(1) only specifies "comm" for the "-o" option but not "ucomm". See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ps.html - On Linux (with the procps-ng package) "ucomm" is an alias for "comm". See https://gitlab.com/procps-ng/procps - OpenBSD also has "ucomm" as an alias for "comm" (with the extra note "Name to be used for accounting."). See https://man.openbsd.org/ps - FreeBSD describes "ucomm" as "Name to be used for accounting." but does not say that it should be an alias for "comm". See https://www.freebsd.org/cgi/man.cgi?query=ps --- src/nvim/lua/vim.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/lua/vim.lua b/src/nvim/lua/vim.lua index e1bbb03d3f..6900313752 100644 --- a/src/nvim/lua/vim.lua +++ b/src/nvim/lua/vim.lua @@ -13,7 +13,7 @@ local function _os_proc_info(pid) if pid == nil or pid <= 0 or type(pid) ~= 'number' then error('invalid pid') end - local cmd = { 'ps', '-p', pid, '-o', 'ucomm=', } + local cmd = { 'ps', '-p', pid, '-o', 'comm=', } local err, name = _system(cmd) if 1 == err and string.gsub(name, '%s*', '') == '' then return {} -- Process not found. From 4d10024a561a20cb2291f5615e4b01957dd955b9 Mon Sep 17 00:00:00 2001 From: Lucas Hoffmann Date: Sat, 18 Aug 2018 14:37:29 +0200 Subject: [PATCH 2/2] API: Remove path prefix from command name in nvim_get_proc() On macOS the output from `ps -o comm` might contain the full path of the executable. The `ucomm` would be the basename only but is less portable (see previous commit). --- src/nvim/lua/vim.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/lua/vim.lua b/src/nvim/lua/vim.lua index 6900313752..47f40da72e 100644 --- a/src/nvim/lua/vim.lua +++ b/src/nvim/lua/vim.lua @@ -23,7 +23,7 @@ local function _os_proc_info(pid) end local _, ppid = _system({ 'ps', '-p', pid, '-o', 'ppid=', }) -- Remove trailing whitespace. - name = string.gsub(name, '%s+$', '') + name = string.gsub(string.gsub(name, '%s+$', ''), '^.*/', '') ppid = string.gsub(ppid, '%s+$', '') ppid = tonumber(ppid) == nil and -1 or tonumber(ppid) return {