2019-08-05

A .linux There are three basic types of processes: interactive, batch and daemon

  1. The user at the command line to run interactively interactive process
  2. Batch process from submission queue and are not associated with the command line

When the lower system utilization time, interactive and batch is ideal for repetitive tasks

Daemon is PID system identification process for any parent process 1, it indicates that the process is always init. init is always the first process when the Linux computer starts, it remains on the system until the computer is turned off. Initialization process using any of his father's death process, without having to wait for the child's status. Therefore, the method used to start the daemon involving forked once or twice, and died in the parent process child process to start performing its normal functions.

Some daemons started by the System V init script, these scripts are scripts run automatically when the system starts, that is the short program, they can survive during a session or regenerated from time to time.

Many daemons now start only when needed, and (has been replaced in the new system inetd) consists of a daemon xinetd start, rather than continuously. xinetd called TCP / IP super server itself started at boot time, it listens assigned to /etc/inetd.conf or port processes /etc/xinetd.conf profile listed. Examples daemon crond include remote start it into the Scheduled Tasks, ftpd file transfer, lpd laser printing, rlogind remote login, rshd remote command execution, telnetd.

In addition to start by the operating system and applications, you can also start some daemons manually. Start the daemon program command examples include binlogd binary event logging to a specified file, mysqld database server, apache Apache Web server

In many Unix-like operating systems (including Linux), each daemon has a script (i.e., short program) can use the script terminates, resume, or check the status. Based on the processing of these scripts run level . Run level is a system configuration or operating state, there is only allows certain selected processes. Boot to different run levels can help solve some of the problems, including the repair system errors.

Two .nohup and daemon

nohup is poor as a way to process daemon running in practice, when you want to start a one-time long-running process that should continue when the shell exits, we will use nohup, but also want to use it with stdin background and redirect together. One-time work is not worth making a daemon, but some property daemon is still useful for nohup job.

Regularly regularly scheduled tasks to run best by cron or some other scheduler. Daemon best suited to supervise repetitive tasks can not predict the start time. Usually there is no clear end time daemon, which closed by the user or another process or system display stops. Daemons typically in response to an application or other conditions of service. Other daemons condition and perform a polling response operation.  

In Unix variant, the terminal process associated with the process. Therefore, when the terminal exits the process, because of this association, the process will stop, when the terminal stops, nohup will prevent the process exits. The daemon is started when a process started by the system, which runs until shut down without the user explicitly require it, therefore, part of the process is not the guardian of user interaction, which belong to the system.

III. How to determine whether the process pool of a process finished?

while thread_name is_alive():

  pass -> it will wait for the thread to complete, and then proceed to the next part of the script

Or thread.join () suspends the current process has been started and waits for the completion of the thread

Once a thread of activities began, the thread is believed to be alive, when its run () method terminates, it will cease their activities, or through an unhandled exception, is_alive () method to test whether the thread is alive.

  1. After the python default parameters to create threads, regardless of whether the main thread is finished, will be waiting for child thread is finished with only exit, whether as the result of join
  2. If you create a thread, and set the execution result daemon is true, that is thread.setDaemon (True), the main process executed automatically exit after completion, will not wait for the child threads. But with the main process exits, the child process is also perish.
  3. The role of the join method is blocked, waiting for the child thread ends, join a method parameter is the timeout, that is, if the main thread wait timeout, if the child process has not ended, the main process to force the end of the child process.
  4. If the daemon property is false, then join in the timeout parameter is not valid, still blocks the timeout time, but the main thread will wait until the end of the child thread
  5. If the thread daemon property is True, then join in the timeout parameter is valid, the main thread waits timeout after time, end child thread. If there are N sub-thread join (timeout) at the same time, then in fact the main thread will wait for the timeout period of up to N * timeout, timeout because the start time of each sub-sub-thread is a thread on the end of the time-out time.

  6. When the join () do not write, perform their own end after the main thread, the thread continues to execute child

Guess you like

Origin www.cnblogs.com/karenaqi/p/11306806.html