help icon indicating copy to clipboard operation
help copied to clipboard

how do I send var number to ps process list ubuntu in node.js with spawn with options?

Open mahdi00021 opened this issue 2 years ago • 12 comments

Affected URL(s)

No response

Description of the problem

how do I send var number to ps process list Ubuntu in node.js with spawn?

I have a var number for example : NUMBER_X : 12345

I want that send number to process in list ps process ubuntu My code is this:

const rclone = require("rclone.js");

const task = new Promise((resolve, reject) => {
const subprocess = rclone.copy(source, dest, {

  "env":{
  ...process.env,
  NUMBER_X:1234
  },
  detached: true,
  stdio: 'ignore',
  'use-json-log': true,
  transfers: 100,
  'log-level' : 'INFO',
  'max-backlog': 999999,
  stats: '500ms'
});

subprocess.unref();


});

task.then((code) => {
  code === 0 ? console.log("complete") : null;
});

I want when type:

ps -ef | grep rclone

Then I want to see NUMBER_X in list process Ubuntu

i used of rclone.js that use of spawn child process i want that send var number like x =1233 to process in ps list Ubuntu through options because we must get list running process and should I send id to each process in ps -ef | grep rclone

mahdi00021 avatar Sep 15 '22 13:09 mahdi00021

I'm having trouble understanding what you are trying to achieve, maybe if explain why that would be helpful.

aduh95 avatar Sep 15 '22 13:09 aduh95

@aduh95 i used of rclone.js that use of spawn child process i want that send var number like x =1233 to process in ps list Ubuntu through options because we must get list running process and should I send id to each process in ps -ef | grep rclone

mahdi00021 avatar Sep 15 '22 14:09 mahdi00021

That sounds like a XY problem, I'm confused about:

  • why you need ps? That seems like an odd requirement, are you trying to get this number from another process or something?
  • why use that rclone library instead of node:child_process API? I'm not familiar with it, does it have the same API?
  • What do you mean by "var number"? Is the number changing after the child process starts?

aduh95 avatar Sep 15 '22 17:09 aduh95

@aduh95 we want that get list process in Ubuntu with node.js after for each process send a id like 1245 to each process

Rclone.js is library for copy folder from source to dest For example : from local disk to api cloud storage or local to local

var number is : variable number like 1234 I write in env:{ NUMBER_X : 1235 }

mahdi00021 avatar Sep 15 '22 18:09 mahdi00021

Did you consider using IPC channel to communicate that number to the parent process instead of ps? See https://nodejs.org/api/process.html#event-message for more info.

aduh95 avatar Sep 15 '22 18:09 aduh95

@aduh95 We must using of detached : true stdio : ignore And we send id mean 1234 to each process And we see id in ps list process

mahdi00021 avatar Sep 15 '22 19:09 mahdi00021

@aduh95 We consider an ID for each command and determine the name of the log file based on the ID And in the next step, when we want to get the list of commands with this command : ps -ef | grep rclone The ID of the rclone command is not clear for which file is the log?

mahdi00021 avatar Sep 16 '22 16:09 mahdi00021

@mahdi00021 wouldn't using the PID the most logical thing to do? It's accessible from process.pid, and it's also in the output of ps.

aduh95 avatar Sep 16 '22 17:09 aduh95

@aduh95 Is it possible to get the pid at the time of execution?

mahdi00021 avatar Sep 17 '22 06:09 mahdi00021

There's also subprocess.pid that gives you the PID from the parent process, is that what you are looking for? It is only accessible at the time of execution (unless you store it somewhere to use it afterwards), I'm not sure what you mean.

aduh95 avatar Sep 17 '22 11:09 aduh95

@aduh95 I want to get the pid at the time of execution and save it as a log file and later identify the command from the list of commands ps with the same pid .

mahdi00021 avatar Sep 17 '22 12:09 mahdi00021

const cp = require('node:child_process').spawn('your-program');

console.log(cp.pid); // You can get the PID here.

I don't know what more to tell you, is that what you call "execution time"?

aduh95 avatar Sep 17 '22 13:09 aduh95

There has been no activity on this issue for 11 months. The help repository works best when sustained engagement moves conversation forward. The issue will be closed in 1 month. If you are still experiencing this issue on the latest supported versions of Node.js, please leave a comment.

github-actions[bot] avatar Oct 29 '23 01:10 github-actions[bot]

Closing after no activity on this issue for 12 months.

github-actions[bot] avatar Nov 28 '23 01:11 github-actions[bot]