https://github.com/zikaari/pid-cwd
Node.js lib to get the current working directory of given process id - cross platform
https://github.com/zikaari/pid-cwd
Last synced: 5 days ago
JSON representation
Node.js lib to get the current working directory of given process id - cross platform
- Host: GitHub
- URL: https://github.com/zikaari/pid-cwd
- Owner: zikaari
- License: mit
- Created: 2017-11-24T08:41:53.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-08T08:42:41.000Z (almost 6 years ago)
- Last Synced: 2025-02-02T21:16:57.740Z (19 days ago)
- Language: C++
- Size: 45.9 KB
- Stars: 11
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pid-cwd
Node lib to get the current working directory of given process id - cross platform*
## Usage### Install
```bash
$ npm i pid-cwd
```### Use
```javascript
const pidCwd = require('pid-cwd');pidCwd(54671)
.then(cwd => {
// A check is recommended, cwd could be null sometimes (read note below)
console.log(cwd); // > /home/chipto/Dropbox
});```
## Note
`pid-cwd` will simply return `null` if process doesn't exist, or process is owned by root/administrator or is unreachable or any other reason.
It won't throw any `EPERM` error or anything like that. It does throw if it can't recognize the OS or given `pid` is not a positive number.\* Works as long as `process.platform` === `win32`, `linux` or `darwin`.
Throws if it's not one of those, in that case `require` manually from `pid-cwd/lib/$1` where `$1` is `win`, `linux` or `macos`## External Licenses
Massive thanks to Giampaolo Rodola' and contributors, for their amazing work on [psutil](https://github.com/giampaolo/psutil)
`lib/win_pwdx/` contains 99.97% of code borrowed from [`psutil/arch/windows/process_info.c`](https://github.com/giampaolo/psutil/blob/master/psutil/arch/windows/process_info.c)
`psutil` is BSD licensed, see [`psutil/LICENSE`](https://github.com/giampaolo/psutil/blob/master/LICENSE) for more information.