• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2// Original test written by Jakub Lekstan <kuebzky@gmail.com>
3const common = require('../common');
4
5// FIXME add sunos support
6if (common.isSunOS)
7  common.skip(`Unsupported platform [${process.platform}]`);
8// FIXME add IBMi support
9if (common.isIBMi)
10  common.skip('Unsupported platform IBMi');
11if (!common.isMainThread)
12  common.skip('Setting the process title from Workers is not supported');
13
14const assert = require('assert');
15const exec = require('child_process').exec;
16const path = require('path');
17
18// The title shouldn't be too long; libuv's uv_set_process_title() out of
19// security considerations no longer overwrites envp, only argv, so the
20// maximum title length is possibly quite short.
21let title = String(process.pid);
22
23assert.notStrictEqual(process.title, title);
24process.title = title;
25assert.strictEqual(process.title, title);
26
27// Test setting the title but do not try to run `ps` on Windows.
28if (common.isWindows)
29  common.skip('Windows does not have "ps" utility');
30
31// To pass this test on alpine, since Busybox `ps` does not
32// support `-p` switch, use `ps -o` and `grep` instead.
33const cmd = common.isLinux ?
34  `ps -o pid,args | grep '${process.pid} ${title}' | grep -v grep` :
35  `ps -p ${process.pid} -o args=`;
36
37exec(cmd, common.mustSucceed((stdout, stderr) => {
38  assert.strictEqual(stderr, '');
39
40  // Freebsd always add ' (procname)' to the process title
41  if (common.isFreeBSD || common.isOpenBSD)
42    title += ` (${path.basename(process.execPath)})`;
43
44  // Omitting trailing whitespace and \n
45  assert.strictEqual(stdout.replace(/\s+$/, '').endsWith(title), true);
46}));
47