Home IT Linux Windows Database Network Programming Server Mobile  
  Home \ Linux \ Daemon under Linux     - How do you know your public IP terminal in Linux (Linux)

- To compile and install MySQL 5.7.7 RC under CentOS 7.1 (Database)

- Four levels to deal with Linux server attacks (Linux)

- Java-based data source database access (Programming)

- Present Situation and Development Trend of firewall products (Linux)

- Swift 2.0 brief (Linux)

- Android project and coding specifications (Programming)

- Thrift 0.9.3 compiler installation under Ubuntu (Linux)

- OpenGL ES 3.0 vertex buffer (Programming)

- Install Java 8 on Ubuntu using PPA (Linux)

- Source install Python3.4 on CentOS (Linux)

- Linux system ARP attack solution (Linux)

- Vi / Vim prompt solutions do not have permission to save time (Linux)

- How to Disable Linux IPv6 (Linux)

- Spring AOP for logging (Programming)

- To install the Contiki development toolchain on Ubuntu (Linux)

- Linux system security check notes on performance (Linux)

- Linux kernel panic (because glibc result) Repair (Linux)

- Ubuntu 14.10 users to install Audio Recorder 1.5.7 (Linux)

- Use web2py + uWSGI + Nginx Web server built on Linux (Server)

  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}.
- Performance comparison Fibonacci recursive and non-recursive (Programming)
- in no backup ex: error: Xin Tourou ah backup child process has Singles DAT / US person / bin / in no backup ex (Database)
- LVM management parameters commonly used commands explained in detail (Linux)
- Oracle Linux 6.4 installed Oracle 11gR2 + RAC + ASM (Database)
- The most common and most effective security settings under linux (Linux)
- Android Studio Personalization (Linux)
- Iptables principle (Linux)
- Job achieve automation in Ubuntu 14.04 - Using Cron (Linux)
- installation of Piwik under Ubuntu (Programming)
- Redis performance test (Database)
- Chkconfig command Detailed service is added and shut down the system in two ways to start service under Linux (Linux)
- Zabbix monitoring disk IO status (Server)
- How to manage your to-do list with the Go For It on Ubuntu (Linux)
- Implicit conversion from Java type conversion compare MySQL and Oracle (Database)
- Bitmap memory footprint of computing Android memory optimization (Linux)
- Simple Calendar C language (Programming)
- Ubuntu and Derivative Edition users install LMMS 0.4.15 (Linux)
- For the FreeBSD install Adobe Flash plug-in (Linux)
- Nginx load balancing configuration (http proxy) (Server)
- build Android environment on Ubuntu 12.04 (Server)
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.