In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
How to carry out the daemon implementation of the Python process, many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can get something.
Python process is a computer language in practical application. If you encounter related problems in the process of practical application, you can introduce its practical application in detail through the following article. The following is a specific introduction of the article. I hope you will get something.
Python process
Daemon: usually defined as a background process, and it does not belong to any terminal session (terminal session). Many system services are implemented by daemons, such as network services, printing, etc. Here are the steps for writing a daemon written by a netizen:
1. Call fork () so that the parent process can exit, and the Python process returns control to the command line or shell program running your program. This step is required to ensure that the new process is not a process group leader process (process group leader). The next step, setsid (), will fail because you are the leader of the process group.
two。 Call setsid () to become the leader process of a process group and session group. Because a control terminal is associated with a session, and the new session has not yet acquired a control terminal, our process does not have a control terminal, which is a good thing for the daemon.
3. Fork () is called again, so the parent process (the session group leader process) can exit. This means that we, a non-session group leader process, can never regain control of the terminal.
4. Call chdir ("/") to confirm that our process does not keep any directories in use. Not doing this will cause the system administrator not to umount a file system because it is our current working directory. [similarly, we can change the current directory to the directory where the daemon runs important files]
5. Call umask (0) so that we have complete control over everything we write. We don't know what kind of umask we inherited. [this step is optional] (translator's note: this refers to step 5, because the daemon does not necessarily need to write a file)
6. Call close () to close the file descriptors 0pm 1 and 2. In this way we release the marked input, standard output, and standard error output inherited from the parent process. There is no way to know where these Python process text descriptors may have been redirected. Notice that many daemons use sysconf () to confirm the limitations of _ SC_OPEN_MAX. _ SC_OPEN_MAX tells you the maximum number of files each process can open.
Then using a loop, the daemon can close all possible file descriptors. You have to decide whether you need to do this or not. If you think there are open file descriptors, you need to close them because the system has a limit on the number of files that can be opened at the same time.
7. Create new file descriptors for standard input, standard output, and standard error output. Even if you're not going to, it's a good idea to use them and open them. Accurate manipulation of these descriptors is based on your own preferences; for example, if you have a log file, you may want to open it as standard output and mark error output, and / dev/null as standard input
As an alternative, you can use / dev/console as standard error output and / or open / dev/null as standard input, or any combination of its Python process that makes sense to your daemon.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
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.