In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how nodejs ends a process". In daily operation, I believe many people have doubts about how nodejs ends a process. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts about "how to end a process in nodejs"! Next, please follow the editor to study!
In nodejs, you can use the kill () method of the Process object to end a process, which can send a signal to the process identified by pid to kill the process group; syntax "process.kill (pid,'SIGTERM')".
This tutorial operating environment: windows7 system, nodejs version 12.19.0, DELL G3 computer.
NodeJS ends the process
The Process object is a global variable that provides information about and controls the current Node.js process. As a global variable, it is always available to Node.js applications without the use of require (). It can also use require () to explicitly access the
Process.kill (pid [, signal]) method
Added on: v0.0.06 (node)
Pid process PID
Signal | the signal to be sent. The type is a string or a number. Default value: SIGTERM.
The process.kill () method sends the signal to the process identified by pid
The signal name is a string such as' SIGINT' or 'SIGHUP'. For more information, see signal events and kill (2).
If the target pid does not exist, the method throws an error. As a special example, signal 0 can be used to test the existence of a process. On the Windows platform, an error is thrown if pid is used to kill a process group.
Even though the name of this function is process.kill (), it just sends a signal, which is similar to the kill system call. The signal sent may be to do something that has nothing to do with killing the target process.
A simple and crude code demonstration
First take a look at the official website documentation gentle code demonstration
Process.on ('SIGHUP', () = > {console.log (' receiving SIGHUP signal');}); setTimeout () = > {console.log ('exiting'); process.exit (0);}, 100); process.kill (process.pid, 'SIGHUP')
Demonstrate directly in a simple and rude way
I don't write the code carefully because of my working hours, but the overall idea is the same.
Requirements: go to the computer to see your own process pid to get your own corresponding pid and fill it into the variable. After completing the coding, use node to compile the code-> execute.
Node process.jslet pid = 11784According to the pid of the application on my PC, you can fill in the process.kill (pid, 'SIGTERM') according to the pid of your computer; / / end the pid process at this point, the study on "how nodejs ends a process" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.