Several Methods for reliable running of processes on the background and several methods on the background

Source: Internet
Author: User

Several Methods for reliable running of processes on the background and several methods on the background

Cron

A) in linux, the next program that automatically executes a specified task contains "time", "path", "Automatic Execution script", and other elements. It has the following features:

B) Command Parsing

1. Start, restart, and close Cron

# Service crond start/restart/stop

2. Browse the existing Cron list

# Crontab-l

3. Edit the crontab of the current user, for example:

1). 9 9 ***/usr/local/bin/cvsb // indicates that the cvsb file in the/usr/local/bin/directory is executed at 09:09 every morning.

2). 3 3 ** 0/usr/local/bin/qbbak // indicates that the qbbak file in the/usr/local/bin directory is executed at 03:03 every Sunday.

3 ). **/6 **/usr/local/bin/esbbak // indicates that the execution is performed every six hours. The execution time starts from the first execution. Of course, you can also customize the execution time, for example, if 0 */6 *, the program will be executed on the entire point.

4). ***/usr/local/bin/esbak // indicates that the execution is performed at and every hour.

5) * 23 ** 2-5/usr/local/bin/esbbak // indicates execution at every day from Tuesday to Friday.

Daemon

A) a special process (daemon process) running in the background, independent of the control terminal and periodically executes a task or waits for processing certain events.

B) in Linux, a function is provided to implement daemon. The prototype of this function is as follows: int daemon (int _ nochdir, int _ noclose ); if the value of nochdir is 0, the working directory will be switched to the root directory. If noclose is 0, standard input, output, and standard errors will be redirected to/dev/null.

C) The Daemon generally starts running when the system is started. Unless it is forcibly terminated, it remains running until the system is shut down;

D) daemon often run with the root permission because they use special ports (1-1024) or access certain special resources.

E) the daemon processes open a port and Listen (Listen) to wait for the client to connect. If the client generates a connection request, the daemon creates a (Fork) subserver to respond to the connection, and the master server continues to listen to other service requests.

A) Add nohup before the command to be processed. By default, standard output and standard errors are redirected to the nohup. out file.

B) Add "&" to the end to run the command in the background at the same time. For example: nohup ping www.ibm.com &

A) The application needs to run continuously for 24 hours. In this case, the supervisor can be used to monitor the process of the application. When an internal application error exits or the process is killed, the application is automatically restarted.

B) install the supervisor.

C) Configure supervison

D) Start

E) Add supervisord to serve the Linux system and start automatically upon startup.

Copy supervisord. conf to the/etc directory.

STARTUP script supervisord. sh

#! /Bin/sh

#

#/Etc/rc. d/init. d/supervisord

#

# Supervisor is a client/server system that

# Allows its users to monitor and control

# Number of processes on UNIX-like operating

# Systems.

#

# Chkconfig:-64 36

# Description: Supervisor Server

# Processname: supervisord

# Source init functions

./Etc/rc. d/init. d/functions

Prog = "supervisord"

Prog_bin = "/usr/local/bin/supervisord"

PIDFILE = "/tmp/supervisord. pid"

Start ()

{

Echo-n $ "Starting $ prog :"

# Source init functions

./Etc/rc. d/init. d/functions

Prog = "supervisord"

Prog_bin = "/usr/local/bin/supervisord"

PIDFILE = "/tmp/supervisord. pid" start ()

{

Echo-n $ "Starting $ prog :"

Daemon $ prog_bin -- pidfile $ PIDFILE

[-F $ PIDFILE] & success $ "$ prog startup" | failure $ "$ prog startup"

Echo

}

Stop ()

{

Echo-n $ "Shutting down $ prog :"

[-F $ PIDFILE] & killproc $ prog | success $ "$ prog shutdown"

Echo

}

Case "$1" in

Start)

Start

;;

Stop)

Stop

;;

Status)

Status $ prog

;;

Restart)

Stop

Start

;;

*)

Echo "Usage: $0 {start | stop | restart | status }"

;;

Esac

Add as System Service

# Mv supervisord. sh/etc/init. d/supervisord

# Chkconfig -- add supervisord

# Chkconfig -- level 345 supervisord on

A) Screen is a window manager that can reuse a physical terminal among multiple processes.

B) Screen command

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.