[Linux] PHP programmers play with the Linux series-using supervisor to implement daemon and supervisor daemon
1. PHP programmers turn to the Linux series-how to install and use CentOS
2. PHP programmers play with Linux series-lnmp Environment Construction
3. PHP programmers play with the Linux series-build an FTP code Development Environment
4. PHP programmers turn to the Linux series-back up and restore MySQL
5. PHP programmers turn to the Linux series-automatic backup and SVN
6. PHP programmers go to Linux-install nginx on Linux and Windows
7. PHP programmers play with Linux series-nginx beginner Guide
8. PHP programmers play with the Linux series-HTTPS in Nginx
The first problem I encountered was that when I deployed the blog program of nodejs, I put the command for executing nodejs in the background and used the Add & and nohup commands.
For example: nodejs index. js & or nohup nodejs index. js &
& This operation stops when the terminal session is exited. In theory, the nohup command can be executed all the time in the background, but will exit when some exceptions occur.
Basic concepts of processes
A process is a process of executing a program. the ppid of the kernel process of the unix system is 0. For example, the pid of the init process is 1 and the ppid is 0. Other processes are fork Based on the init process, run the pstree command to view the process tree.
Test and use & implement a background process, and then switch the background process back to the foreground. The following shows how to put the process in the background. [1] This is the job number.
ping baidu.com > xx.txt &
Re-transfer the background process to the foreground. The number of % 1 is the job number above.
fg %1
How to Use the nohup command
Nohup command, which causes the process to ignore the SIGHUP hangup signal. The test is as follows:
nohup ping baidu.com > xx.txt &
The process signal is as follows:
01 SIGHUP suspension (hangup) 02 SIGINT interruption. When you press ^ c or ^ break on the keyboard, 03 SIGQUIT exits, when a user presses the quit key from the keyboard, the 04 SIGILL illegal command 05 SIGTRAP trace trap starts the process, tracking code execution 06 sigiot iot command 07 SIGEMT command 08 SIGFPE floating point operation overflow 09 SIGKILL killing and killing processes 10 SIGBUS Bus Error 11 SIGSEGV segment violation (segmentation violation ), A process attempts to access a location other than its virtual address space 12 SIGSYS System Call parameters are incorrect, for example, the system call number is invalid 13 SIGPIPE writes data to a non-read pipeline 14 SIGALRM alarm clock. When a process wants to receive a signal after a certain time, this signal is 15 SIGTERM software termination) 16 SIGUSR1 User-Defined signal 117 SIGUSR2 User-Defined signal 218 SIGCLD a sub-process dead 19 SIGPWR Power Failure
Use supervisor to implement daemon
A daemon is a process that has been running for a long period of time. The supervisor can be used to implement such a process and will automatically restart it when it is killed.
# Install supervisoryum install supervisor
Configure in the configuration file (/etc/supervisord. conf:
Program: nodejsblog here: it is followed by a name.
Command = the command to be executed
User = here is the execution user
[program:nodejsblog]command=/usr/bin/nodejs /var/www/html/nblog index.js user=root
Enable supervisord-c/etc/supervisord. conf
At this time, the node. js daemon will be started. You can run the ps command to check the daemon, and it will be automatically restarted when you kill the process.
For example, test the deployed nodejs website http://nblog.qingguow.cn in this example
Blog related to this:
[Nodejs] nodejs development blog (7) log on to taoshihan at the backend reading: 1002 comments: 0 [nodejs] nodejs development blog (6) Data paging Tao shihan reading: 348 comments: 0 [nodejs] nodejs development blog (5) distribution of data Tao shihan read: 88 comments: 0 [nodejs] nodejs development blog (4) data Model Tao shihan reading: 98 comments: 0 [nodejs] nodejs development personal blog (3) Loading page Tao shihan views: 114 comments: 0 [nodejs] nodejs development blog (2) entry file Tao shihan read: 218 comments: 0 [nodejs] nodejs development blog (1) preparations Tao shihan read: 207 comments: 0