You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unix users can override the default `ps` arguments:
65
+
```ts
66
+
lookup({
67
+
command: 'node',
68
+
psargs: 'ux'
69
+
}, (err, resultList) => {
70
+
// ...
71
+
})
72
+
```
70
73
74
+
Specify the `ppid` option to filter the results by the parent process id (make sure that your custom `psargs` provides this output: `-l` or `-j` for instance)
75
+
```ts
76
+
lookup({
77
+
command: 'mongod',
78
+
psargs: '-l',
79
+
ppid: 82292
80
+
}, (err, resultList) => {
81
+
// ...
82
+
})
71
83
```
72
84
73
85
### kill()
74
86
Eliminates the process by its `pid`.
75
87
76
-
```javascript
77
-
var ps =require('@webpod/ps');
88
+
```ts
89
+
import { kill } from'@webpod/ps'
78
90
79
-
// A simple pid lookup
80
-
ps.kill( '12345', function( err ) {
81
-
if (err) {
82
-
thrownewError( err );
83
-
}
84
-
else {
85
-
console.log( 'Process %s has been killed!', pid );
86
-
}
87
-
});
91
+
kill('12345', err=> {
92
+
if (err) {
93
+
thrownewError(err)
94
+
} else {
95
+
console.log('Process %s has been killed!', pid)
96
+
}
97
+
})
88
98
```
89
99
90
100
Method `kill` also supports a `signal` option to be passed. It's only a wrapper of `process.kill()` with checking of that killing is finished after the method is called.
91
101
92
-
```javascript
93
-
var ps =require('@webpod/ps');
102
+
```ts
103
+
import { kill } from'@webpod/ps'
94
104
95
105
// Pass signal SIGKILL for killing the process without allowing it to clean up
96
-
ps.kill( '12345', 'SIGKILL', function( err ) {
97
-
if (err) {
98
-
thrownewError( err );
99
-
}
100
-
else {
101
-
console.log( 'Process %s has been killed without a clean-up!', pid );
102
-
}
103
-
});
104
-
```
105
-
106
-
you can use object as the second parameter to pass more options:
107
-
108
-
```js
109
-
ps.kill( '12345', {
110
-
signal:'SIGKILL',
111
-
timeout:10, // will set up a ten seconds timeout if the killing is not successful
112
-
}, function(){});
113
-
106
+
kill('12345', 'SIGKILL', err=> {
107
+
if (err) {
108
+
thrownewError(err)
109
+
} else {
110
+
console.log('Process %s has been killed without a clean-up!', pid)
111
+
}
112
+
})
114
113
```
115
114
116
-
Notice that the nodejs build-in `process.kill()` does not accept number as the signal, you will have to use string format.
117
-
118
-
119
-
You can also pass arguments to `lookup` with `psargs` as arguments for `ps` command(Note that `psargs` is not available in windows):
You can also use object notation to specify more opts:
116
+
```ts
117
+
kill( '12345', {
118
+
signal: 'SIGKILL',
119
+
timeout: 10, // will set up a ten seconds timeout if the killing is not successful
120
+
}, () => {})
140
121
```
141
122
142
-
Lastly, you can filter a list of items by their PPID by passing a PPID to filter on. You will need to pass in a `psarg` that provides the PPID in the results (`-l` or `-j` for instance).
0 commit comments