Read the Communication Equipment monitoring program Some of the notes, not willing to throw, record down!
The difference between _exit () and exit:
Header file:
Exit: #include <stdlib.h>
_exit: #include <unistd.h>
_exit () function: Directly make the process stop running, clear its use of memory space, and destroy its various data structures in the kernel;
The exit () function makes some packaging on these bases, adding a number of steps before the exit is executed.
The most important difference between the exit () function and the _exit () function is that the exit () function checks the opening of the file before calling the _exit () system call, and writes the contents of the file buffer back to the file.
Exit (0) indicates that the process exited normally, and no 0 indicates an exception exit.
Strlen () computes the number of characters in an array of characters, with "a" as the end, and does not calculate the array element as ' \ s '.
sizeof calculates the amount of memory space that the data (including arrays, variables, types, structures, and so on) occupies, expressed in bytes.
Char str[20]= "0123456789";
int A=strlen (str); a=10;
int b=sizeof (str); and b=20;
The value of int *p;sizof (p) is 4.
Setbuf (stdout,null); suppress buffering of standard output
#include <iostream> #include <fstream>int main (int argc, char* argv[]) { char* outbuf = new char [100] ; Setbuf (STDOUT,OUTBUF);//bind the output stream to Outbuf puts ("helloworld\n");//content input into Outbuf//setbuf (stdout,null);// If this line of code is enabled, the output stream reverts to its original state and puts output to console delete[] outbuf; System ("pause"); return 0;}
Softdog Analysis
Softdog.c-->int Main (int argc, char *argv[])-->all_init ();
Get the module configuration file name (the ID of the dependent module gets the name of the resource)
Getresnamebymoduleid (rid_file_module_conf, Mid_soft_dog,
filename, sizeof (filename))) = = rst_success)
int getresname (const int ARESID, char *abuff, const int abufflen) Gets the name of the resource (config file)
int Getprogramabsolutepath (char *aabspath, const int Aabspathlen) obtains the absolute path of the program in/SRC/COMMON/COMMUTILS/FILENAMINGINTF.C
defined in the.
|
|
--Get Log Configuration This procedure establishes the name of the configuration file obtained in the previous step filename
Readlogconfig (FileName, &logconfig) reads the log configuration from the configuration file into the logconfig struct-body variable.
#define Log_config_section The segment name of "LogConfig"//Log Configuration
--open log (read config, create output queue and output thread, output thread is responsible for outputting log information to console and file, implement:
void *outputthread (void *argument))
Openlog (Module_name_soft_dog, &logconfig)
Pthread_mutex_init (&s_exitmutex, NULL);
Pthread_mutex_lock (&s_exitmutex);
Pthread_mutex_unlock (&s_exitmutex); The operation for the thread lock, which is used for mutually exclusive operations when accessing shared files between threads.
Regthread (Pthread_self (), thread_name_main_thread)//The name ID number information for the thread (this is the main thread) is recorded in a struct array.
is not a system call.
Summary 1, in All_init (), completed the following work:
1, get the configuration file name and file path of each module;
2. Gets information about the log configuration in the module configuration file, which is stored in the LOGCONFIG structure variable.
3. Open the log, read the LogConfig log configuration, create the output queue and output thread, and the output thread is responsible for outputting the log information to the console and file.
4. Register the thread information and get the path to the application.
Sed-i '/^0x0102=/r Log.ini ' Desktop/release/app/config/dev/a09b4000/repparamsconf.ini
This command can add a line directly below the original file
①char *strcpy (S,CT)//Copy the string into the string s, and return S.
②void *memset (void*s,int ch, size_t N)//will replace the first n bytes in s with ch and return S. Function: Fills a block of memory with a given value
, which is commonly used to clear 0 operations on large structures and arrays. such as: memset (keyValue, 0, sizeof (keyValue));//zeroing the array.
③fork ()
④execl (Programfile, Programfile, "", NULL)
The role of fork is to replicate a new process based on an existing process, which is called the parent process, and the new process is called the child process
Process). Entering a command under the shell can run a program because the shell process calls fork after reading the user input command to copy a new
Shell process, and then the new shell process calls exec to execute the new program.
⑤exit (exit_failure);
⑥sprintf (Abuff, "%s/%s%s", S_path, Module_name_soft_dog, file_postfix_config);
⑦pthread_t pthread_self (void);
Function: Gets the ID of the thread itself. The type of pthread_t is unsigned long int, so use%lu mode when printing, otherwise it will produce magical results.
⑧//Creating message Queues
S_ctrlqueueid = Msgget (S_ctrlqueuekey, ipc_creat | 0666);
Read the code with a note (1)