Home IT Linux Windows Database Network Programming Server Mobile  
  Home \ Linux \ Daemon under Linux     - KVM QEMU virtual machine installation configuration under CentOS (Linux)

- Ubuntu simple method to track multiple time zones (Linux)

- Selection sort, insertion sort, and Shell sort (Programming)

- Use Python automatically cleared Android Engineering excess resources (Programming)

- CentOS7 installation configuration (Server)

- The basic principles for the protection of a good linux server security (Linux)

- How to install Unbound and DNSCrypt in Archlinux (Server)

- Open container cluster management system architecture and components introduced Kubernetes (Server)

- Use install_updates upgrade GAMIT / GLOBK (Linux)

- Use Vagrant up a local development environment tutorials (Server)

- The top command under Linux (Linux)

- MySQL various log summary (Database)

- Linux6.1 / 6.5 dual-NIC Binding (Linux)

- Ubuntu 15.04 installed Nvidia Quadro series graphics driver (Linux)

- How to install Laravel PHP framework on CentOS 7 / Ubuntu 15.04 (Server)

- How MySQL tracking sql statement (Database)

- Vagrant failed to start, stuck in Waiting for VM to boot solution (Linux)

- Basic data types JavaScript type system and the type of packaging (Programming)

- DELL D630 Wireless LAN Driver Installation CentOS6 (Linux)

- Customize own small private Linux system (Linux)

  Daemon under Linux
  Add Date : 2017-08-31      
  The role of the Permanent process under Linux can not be ignored, but there is a problem can not be ignored, how to start the process, how the end of the process, how the process should be restarted after the process hangs rational design. Let's look at an example of a control shell php permanent process.

No nonsense, direct fishing dry goods, the code through the code easier to understand to explain:

#! / Bin / sh
#filename test.sh
# Absolute positioning location of the file, but does not change with the implementation of the directory
cd $ (cd "$ (dirname" $ 0 ")"; pwd)
readonly path = $ (pwd) /
file = $ 1;
RunFile = "$ {path} data / $ {file} .run"
DieFile = "$ {path} data / $ {file} .die"
readonly file = "$ {path} $ {file} .php"
if [! -f "$ file"]; then
    echo "please select a exists file"
elif [! -f "$ RunFile"]; then
# Here to determine if RunFile file does not exist, it indicates that the process does not exist, start the process below echo $$> $ {RunFile}
    while true
            if [! -f $ DieFile]; then
            # Here if DieFile file does not exist, then program execution continues, otherwise go else, an exit
                / Usr / bin / php -f $ {file}
                touch $ RunFile
                sleep 1
            # If the file exists DieFile Clear RunFile and DieFile exit
                if rm -rf $ RunFile && rm -rf $ DieFile; then
# Here in the presence of RunFile attempts to start the process
    oldpid = `cat $ RunFile`
    newpid = `ps aux | grep" process.sh $ 1 "| grep -v grep | grep" $ oldpid "| awk '{print $ 2}'`
    if [[$ oldpid -eq $ newpid]]; then
    # If RunFile the goal is the same process ID and process ID is running, indicating that all is well ^ _ ^
        echo "the process is runing now"
    # If RunFile the matching process ID of the target process is not running, it indicates a problem with the process, delete and end the running processes RunFile
        echo "error situation, kill the run process and delete the run file"
        ps aux | grep "process.sh $ 1" | grep -v 'grep' | awk '{print $ 2}' | grep -v $$ | xargs --no-run-if-empty kill
        if [$ -eq 0?]; then
            rm -f $ RunFile
            echo $?> $ {path} / data / error

Only there are several places to be emphasized:

The method I use this shell to call php program, this is no limitation to note here is that this process is running resident
In RunFile exist, but the process is not on the number of scrapping process (that is, the amount of local red else performed) must be `grep -v $$`, the role is to filter out the currently running process, or else have been killed , and will not be behind the implementation of the
There is also a place to note is about the automatic restart
Automatic restart can be placed crontab, every so often executed once, treat specific conditions.

crontab -e
# Open the current user schedule, add mode

# 5 schedule asterisk, f1, f2, f3, f4, f5,
# F1 wherein said points, f2 is represented, f3 represents days, f4 represents months, f5 indicate the day of one week
# * Means every minute / hour / day / month / Sunday, * / n n represents each minute / hour / ...... executed once

* / 2 * * * * /root/test.sh
# 2 minutes did not perform a

Such a process of permanent full functionality is complete, you want to terminate the process is only in the corresponding directory to touch $ {DieFile}.
- Zookeeper Rights Management and Quota Management (Server)
- To update Python version under CentOS system (Linux)
- Java programmers talk about those advanced knowledge and direction (Programming)
- Java Cookie Comments (Programming)
- Linux, modify / retrieve the root password (Linux)
- Linux operation and maintenance engineers face questions Intermediate (Linux)
- Python kills corresponding process according to pid (Programming)
- Linux iostat command example explanation (Linux)
- Security experience: to see how the experts deal with DDoS attacks (Linux)
- Lua4.0 interpreter documents (Programming)
- To install Ganglia configuration of experience under CentOS 5.5 (Linux)
- Configuring xdebug debugging environment in Ubuntu 14.04 under the PhpStorm (Linux)
- Linux RPM default installation path (Linux)
- RedHat Linux source code package installation process (Linux)
- The development environment to build Nodejs under Ubuntu 14.04 (Linux)
- Add a custom encryption algorithm in OpenSSL (Linux)
- How to understand the difference between synchronous and asynchronous non-blocking blocking (Programming)
- CentOS 6.5 three ways to configure the IP address (Linux)
- The headers for the current running kernel were not found when VirtualBox installation enhancements (Linux)
- CentOS6 installed Tomcat (Server)
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.