কম্পিউটার

Node.js এ process.cpuUsage() পদ্ধতি


process.argv() পদ্ধতিটি বর্তমান চলমান প্রক্রিয়ার জন্য ব্যবহারকারী এবং এর cpu ব্যবহার পাওয়ার জন্য ব্যবহৃত হয়। বৈশিষ্ট্য ব্যবহারকারী এবং সিস্টেমের সাথে একটি বস্তুতে ডেটা ফেরত দেওয়া হয়। প্রাপ্ত মানগুলি মাইক্রোসেকেন্ডে, অর্থাৎ 10^-6 সেকেন্ড। যদি একাধিক কোর চলমান প্রক্রিয়ার জন্য কাজ করে তাহলে প্রত্যাবর্তিত মান প্রকৃত অতিবাহিত সময়ের চেয়ে বেশি হতে পারে।

সিনট্যাক্স

process.cpuUsage([previousValue])

পরামিতি

পদ্ধতিটি শুধুমাত্র একটি একক প্যারামিটার গ্রহণ করে যা −

নীচে সংজ্ঞায়িত করা হয়েছে
  • আগের মান - এটি একটি ঐচ্ছিক পরামিতি। এটি process.cpuUsage() পদ্ধতিতে কল করে আগের রিটার্ন মান।

উদাহরণ

cpuUsage.js নামের একটি ফাইল তৈরি করুন এবং নীচের কোড স্নিপেটটি অনুলিপি করুন। ফাইল তৈরি করার পরে, নীচের উদাহরণে দেখানো এই কোডটি চালানোর জন্য নিম্নলিখিত কমান্ডটি ব্যবহার করুন −

node cpuUsage.js

cpuUsage.js

// Node.js program to demonstrate the use of process.argv

// Importing the process module
const process = require('process');

// Getting the cpu usage details by calling the below method
const usage = process.cpuUsage();

// Printing the cpu usage values
console.log(usage);

আউটপুট

admin@root:~/node/test$ node cpuUsage.js
{ user: 352914, system: 19826 }

উদাহরণ

আসুন আরও একটি উদাহরণ দেখি।

// Node.js program to demonstrate the use of process.argv

// Importing the process module
const process = require('process');

// Getting the cpu usage details by calling the below method
var usage = process.cpuUsage();
// Printing the cpu usage values
console.log("cpu usage before: ", usage);

// Printing the current time stamp
const now = Date.now();

// Looping to delay the process for 100 milliseconds
while (Date.now() - now < 100);

// After using the cpu for nearly 100ms
// calling the process.cpuUsage() method again...
usage = process.cpuUsage(usage);

// Printing the new cpu usage values
console.log("Cpu usage by this process: ", usage);

আউটপুট

admin@root:~/node/test$ node cpuUsage.js
cpu usage before: { user: 357675, system: 32150 }
Cpu usage by this process: { user: 93760, system: 95 }

  1. Node.js এ process.chdir() পদ্ধতি

  2. Node.js এ process.argv0() পদ্ধতি

  3. Node.js এ process.argv() পদ্ধতি

  4. Node.js এ process.arch() পদ্ধতি