How to use the os.constants function in os

To help you get started, we’ve selected a few os examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github graalvm / graaljs / test / parallel / test-os-process-priority.js View on Github external
'use strict';
const common = require('../common');
const assert = require('assert');
const os = require('os');
const {
  PRIORITY_LOW,
  PRIORITY_BELOW_NORMAL,
  PRIORITY_NORMAL,
  PRIORITY_ABOVE_NORMAL,
  PRIORITY_HIGH,
  PRIORITY_HIGHEST
} = os.constants.priority;

// Validate priority constants.
assert.strictEqual(typeof PRIORITY_LOW, 'number');
assert.strictEqual(typeof PRIORITY_BELOW_NORMAL, 'number');
assert.strictEqual(typeof PRIORITY_NORMAL, 'number');
assert.strictEqual(typeof PRIORITY_ABOVE_NORMAL, 'number');
assert.strictEqual(typeof PRIORITY_HIGH, 'number');
assert.strictEqual(typeof PRIORITY_HIGHEST, 'number');

// Test pid type validation.
[null, true, false, 'foo', {}, [], /x/].forEach((pid) => {
  const errObj = {
    code: 'ERR_INVALID_ARG_TYPE',
    message: /The "pid" argument must be of type number\./
  };
github graalvm / graaljs / test / parallel / test-child-process-spawnsync-validation-errors.js View on Github external
'use strict';
const common = require('../common');
const assert = require('assert');
const spawnSync = require('child_process').spawnSync;
const signals = require('os').constants.signals;
const rootUser = common.isWindows ? false : process.getuid() === 0;

const invalidArgTypeError = common.expectsError(
  { code: 'ERR_INVALID_ARG_TYPE', type: TypeError },
  common.isWindows || rootUser ? 42 : 62);

const invalidRangeError =
  common.expectsError({ code: 'ERR_OUT_OF_RANGE', type: RangeError }, 20);

function pass(option, value) {
  // Run the command with the specified option. Since it's not a real command,
  // spawnSync() should run successfully but return an ENOENT error.
  const child = spawnSync('not_a_real_command', { [option]: value });

  assert.strictEqual(child.error.code, 'ENOENT');
}
github bnoordhuis / node-heapdump / index.js View on Github external
var flags = kSignalFlag;
var options = (process.env.NODE_HEAPDUMP_OPTIONS || '').split(/\s*,\s*/);
for (var i = 0, n = options.length; i < n; i += 1) {
  var option = options[i];
  if (option === '') continue;
  else if (option === 'signal') flags |= kSignalFlag;
  else if (option === 'nosignal') flags &= ~kSignalFlag;
  else console.error('node-heapdump: unrecognized option:', option);
}
addon.configure(flags);

var os = require('os');
var errno = [];
if (os.constants && os.constants.errno) {
  Object.keys(os.constants.errno).forEach(function(key) {
    var value = os.constants.errno[key];
    errno[value] = key;
  });
}

exports.writeSnapshot = function(filename, cb) {
  if (typeof filename === 'function') cb = filename, filename = undefined;
  var result = addon.writeSnapshot(filename);
  var success = (typeof result === 'string');  // Filename or errno.
  // Make the callback. Yes, this is synchronous; it wasn't back when heapdump
  // forked before writing the snapshot, but it is now. index.js can postpone
  // the callback with process.nextTick() or setImmediate() if synchronicity
  // becomes an issue. Or just remove it, it's pretty pointless now.
  if (cb) {
    if (success) cb(null, result);
    else cb(new Error('heapdump write error ' + (errno[result] || result)));
github raszi / node-tmp / lib / tmp.js View on Github external
* Tmp
 *
 * Copyright (c) 2011-2017 KARASZI Istvan 
 *
 * MIT Licensed
 */

/*
 * Module dependencies.
 */
const fs = require('fs');
const os = require('os');
const path = require('path');
const crypto = require('crypto');
const _c = fs.constants && os.constants ?
  { fs: fs.constants, os: os.constants } :
  process.binding('constants');
const rimraf = require('rimraf');

/*
 * The working inner variables.
 */
const
  // the random characters to choose from
  RANDOM_CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',

  TEMPLATE_PATTERN = /XXXXXX/,

  DEFAULT_TRIES = 3,

  CREATE_FLAGS = (_c.O_CREAT || _c.fs.O_CREAT) | (_c.O_EXCL || _c.fs.O_EXCL) | (_c.O_RDWR || _c.fs.O_RDWR),
github GoogleCloudPlatform / github-actions / setup-gcloud / node_modules / tmp / lib / tmp.js View on Github external
* Tmp
 *
 * Copyright (c) 2011-2017 KARASZI Istvan 
 *
 * MIT Licensed
 */

/*
 * Module dependencies.
 */
const fs = require('fs');
const os = require('os');
const path = require('path');
const crypto = require('crypto');
const _c = fs.constants && os.constants ?
  { fs: fs.constants, os: os.constants } :
  process.binding('constants');
const rimraf = require('rimraf');

/*
 * The working inner variables.
 */
const
  // the random characters to choose from
  RANDOM_CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',

  TEMPLATE_PATTERN = /XXXXXX/,

  DEFAULT_TRIES = 3,

  CREATE_FLAGS = (_c.O_CREAT || _c.fs.O_CREAT) | (_c.O_EXCL || _c.fs.O_EXCL) | (_c.O_RDWR || _c.fs.O_RDWR),
github DefinitelyTyped / DefinitelyTyped / types / node / v6 / node-tests.ts View on Github external
{
        let result: os.CpuInfo[];

        result = os.cpus();
    }

    {
        let result: { [index: string]: os.NetworkInterfaceInfo[] };

        result = os.networkInterfaces();
    }

    {
        let result: number;

        result = os.constants.signals.SIGHUP;
        result = os.constants.signals.SIGINT;
        result = os.constants.signals.SIGQUIT;
        result = os.constants.signals.SIGILL;
        result = os.constants.signals.SIGTRAP;
        result = os.constants.signals.SIGABRT;
        result = os.constants.signals.SIGIOT;
        result = os.constants.signals.SIGBUS;
        result = os.constants.signals.SIGFPE;
        result = os.constants.signals.SIGKILL;
        result = os.constants.signals.SIGUSR1;
        result = os.constants.signals.SIGSEGV;
        result = os.constants.signals.SIGUSR2;
        result = os.constants.signals.SIGPIPE;
        result = os.constants.signals.SIGALRM;
        result = os.constants.signals.SIGTERM;
        result = os.constants.signals.SIGCHLD;
github DefinitelyTyped / DefinitelyTyped / types / node / v6 / node-tests.ts View on Github external
result = os.constants.errno.ENETDOWN;
        result = os.constants.errno.ENETRESET;
        result = os.constants.errno.ENETUNREACH;
        result = os.constants.errno.ENFILE;
        result = os.constants.errno.ENOBUFS;
        result = os.constants.errno.ENODATA;
        result = os.constants.errno.ENODEV;
        result = os.constants.errno.ENOENT;
        result = os.constants.errno.ENOEXEC;
        result = os.constants.errno.ENOLCK;
        result = os.constants.errno.ENOLINK;
        result = os.constants.errno.ENOMEM;
        result = os.constants.errno.ENOMSG;
        result = os.constants.errno.ENOPROTOOPT;
        result = os.constants.errno.ENOSPC;
        result = os.constants.errno.ENOSR;
        result = os.constants.errno.ENOSTR;
        result = os.constants.errno.ENOSYS;
        result = os.constants.errno.ENOTCONN;
        result = os.constants.errno.ENOTDIR;
        result = os.constants.errno.ENOTEMPTY;
        result = os.constants.errno.ENOTSOCK;
        result = os.constants.errno.ENOTSUP;
        result = os.constants.errno.ENOTTY;
        result = os.constants.errno.ENXIO;
        result = os.constants.errno.EOPNOTSUPP;
        result = os.constants.errno.EOVERFLOW;
        result = os.constants.errno.EPERM;
        result = os.constants.errno.EPIPE;
        result = os.constants.errno.EPROTO;
        result = os.constants.errno.EPROTONOSUPPORT;
        result = os.constants.errno.EPROTOTYPE;
github kiibohd / configurator / src / renderer / flash / index.js View on Github external
cmd.on('close', code => {
      setProgress(curr => curr + '\nExited with code ' + code);
      if (code == 0) {
        popupToast(Flashing Successful} onClose={() => popupToast(null)} />);
        previousPanel();
      } else if (code === -os.constants.errno.ENOENT) {
        popupToast(dfu-util not found} onClose={() => popupToast(null)} />);
        setDfuNotFound(true);
        setProgress(curr => curr + ' (dfu-util not found)');
      } else if (code === 74) {
        popupToast(
          dfu-util could not find device in flash mode.}
            onClose={() => popupToast(null)}
          />
        );
        setProgress(curr => curr + ' (dfu-util could not find device in flash mode)');
      } else {
        popupToast(Error Flashing, check log} onClose={() => popupToast(null)} />);
      }
    });
    cmd.on('error', function() {
github bnoordhuis / node-heapdump / index.js View on Github external
Object.keys(os.constants.errno).forEach(function(key) {
    var value = os.constants.errno[key];
    errno[value] = key;
  });
}
github tabarra / txAdmin / src / components / fxRunner / index.js View on Github external
pids.forEach(pid => {
                os.setPriority(pid, os.constants.priority['PRIORITY_'+priority]);
            });
            log(`Priority set ${priority} for processes ${pids.join()}`, context)