Set the executable program as the Linux service startup How to set our own program as a Linux service program, and implement boot up, need to go through the following three steps: 1 put the executable in a place where a Linux system can be found. enter env under Linux terminal | grep PATH, in the output directory is the system can find the location, put our program in one of the directories can be, I put my program serialread in the/usr/local/bin directory. 2 in the directory/etc/init.d/, create a new file with service as file name, in my experiment, set up Serialread file If we open the directory/etc/init.d/, see the file is actually the service program files, each file content is similar, we will see, here the file structure is almost the same. Almost every file has a flag such as Start, stop, restart, and status, yes, the new file we created also has the same structure, but the corresponding executable program is replaced with our own executable program within these flags. As the contents of my Serialread file are as follows: #! /bin/sh ### BEGIN INIT INFO #N =/usr/local/bin/serialread set-e case "$" in start) # Make sure privileges don ' t persist across reboots nohup/usr/local/bin/serialread & ;; stop) pkill Serialread ;; restart) &nBsp; pkill serialread nohup/usr/local/bin/ Serialread & ;; esac exit 0 3 in Catalog/etc/ RC3.D, create a new symbolic connection file that points to the service file established in step 2nd. Open Directory/etc/rc3.d, you can see this is a symbolic connection file (equivalent to a shortcut in Windows), using the command format          LN-SF destination file name connection file name The connection file name is in the format "sxx destination file name". where xx is generally an integer from 1 to 100, which indicates the start priority, the larger the number, the lower the priority, such as service A's run to rely on service B, the xx number of a should be greater than B. Followed by the "target file name" is to see at a glance, know which file is the symbolic connection. Directory/etc/rc3.d/is the directory that is automatically searched when the system starts up, and the target file of the symbolic connection file in the directory will be run, which is the reason why the symbolic connection is established in this directory--run it in order to boot. as in this example, cd/etc/rc3.d/ ln-sf/etc/init.d/ Serialread s99serialread by completing the above 3 steps, you will make one of your executable programs a service of the system, which has several specific ones that we started with. We can control this program with the service command.: Boot: Service Serialread start stop: Service Serialread stop Restart: Service Serialread restart Serialread above is the service name, which is the file name established in step 2nd. 4 Edit the/etc/rc.local file, add the startup script, which reads as follows: #!/bin/sh-e # # rc.local # # This script was executed at the end of each multiuser RUNLEVEL.&NB sp; # Make sure that the script would "exit 0" on Success or any other # value on error. # # in order to enable or disable this script just change the execution   ; # bits. # # by default this Script does NOTHING.           &NBSp;service Serialread start exit 0 so serialread This service can boot up, hehe
Set the executable program as a Linux service startup