Introduction to database functions for memcached source code reading

Source: Internet
Author: User
Preface memcached source code was recently downloaded to prepare for research. But after the download, I found that many library functions have not been seen by myself, so I collected these functions. Later I found that some of the functions I know may not be known, so I should record all the uncommon functions. These functions are learned in man's English manual, so they may be explained.

Preface memcached source code was recently downloaded to prepare for research. But after the download, I found that many library functions have not been seen by myself, so I collected these functions. Later I found that some of the functions I know may not be known, so I should record all the uncommon functions. These functions are learned in man's English manual, so they may be explained.

Preface

Recently I downloaded the memcached source code to prepare for research.
But after the download, I found that many library functions have not been seen by myself, so I collected these functions.
Later I found that some of the functions I know may not be known, so I should record all the uncommon functions.
These functions are learned from man's English manual, so they may be very simple. If you want to learn more, you can ask me or google to learn more.

How memcached works

Assert

Function Description

Abort the program if assertion is false
Determine whether a value is false. If it is false, exit.

This function is mainly used by programmers for testing.
When a variable should be a value, assert can be used to guarantee that the variable is indeed a value.
If an unexpected value is not specified, the program will force exit and output the error message, in the following format:

When the program is officially used, you need to disable the assert function.
Of course, we will not comment one by one.
We can define a macro NDEBUG. After the definition, assert will be invalid.

Header file and Declaration

#include void assert(scalar expression);//sourceassert(argc > 2);//error messagea.out: timedrun.c:94: int main(int, char**): Assertion `argc > 2' failed.Aborted
Alarm

Function Description

Set an alarm clock for delivery of a signal
Set an alarm for timed sending.

This function is mainly used in programs that require semaphores.
Alarm is actually a timeout limit.
Only one alarm can be set, and the following will overwrite the previous one.

Header file and Declaration

#include 
 
  unsigned int alarm(unsigned int seconds);
 
Fork

Function Description

Create a child process
Create a sub-process

Create a child process with the same memory space as the parent process.
However, there are some differences between this sub-process and the parent process.

If fork is successful, the PID of the child process is returned to the parent process, and 0 is returned in the child process.
If-1 is returned, the sub-process creation fails.

Header file and Declaration

#include 
 
  pid_t fork(void);
 
Perror

Function Description

Print a system error message

Output a message to a standard error.
It can be simply understood as outputting a piece of information.

Header file and Declaration

#include 
 
  void perror(const char *s);#include 
  
   const char *sys_errlist[];int sys_nerr;int errno;
  
 
Execvp

Function Description

Execute a file
Execute a file
Is to call another executable program.

Header file and Declaration

#include 
 
  extern char **environ;int execl(const char *path, const char *arg, ...);int execlp(const char *file, const char *arg, ...);int execle(const char *path, const char *arg,          ..., char * const envp[]);int execv(const char *path, char *const argv[]);int execvp(const char *file, char *const argv[]);
 
Sigaction

Function Description

Examine and change a signal action
Check and modify the signal action

Header file and Declaration

#include 
 
  int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
 
Waitpid

Function Description

Wait for process to change state
Wait for the process to modify the status. Simply put, wait for the signal of the sub-process.
If the modification succeeds, the PID of the child process whose status is modified is returned.
If the status is not modified, 0 is returned, and-1 is returned.

WIFEXITED (status) macro is used to indicate whether the sub-process Exits normally. If yes, it returns a non-zero value.
WEXITSTATUS (status) When WIFEXITED returns a non-zero value, we can use this macro to extract the return value of the sub-process.
WIFSIGNALED (status) WTERMSIG (status) When WIFSIGNALED returns a non-zero value, this macro will cause the number of signals of the child process to end

Header file and Declaration

#include 
 
  #include 
  
   pid_t wait(int *status);pid_t waitpid(pid_t pid, int *status, int options);int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options);
  
 
Signal

Function Description

Ansi c signal handling
Ansi c Signal
Sets a callback function for a signal.
When the specified signal is received, the handler function is executed.

Header file and Declaration

#include 
 
  typedef void (*sighandler_t)(int);sighandler_t signal(int signum, sighandler_t handler);
 
Kill

Function Description

Send signal to a process
Sends a signal to a process

Header file and Declaration

#include 
 
  #include 
  
   int kill(pid_t pid, int sig);
  
 
Getrlimit setrlimit

Function Description

Get/set resource limits
Get the maximum resource limit

Header file and Declaration

#include 
 
  #include 
  
   int getrlimit(int resource, struct rlimit *rlim);int setrlimit(int resource, const struct rlimit *rlim);
  
 
Getuid

Function Description

Get user identity
Obtain the user ID.

Header file and Declaration

#include 
 
  #include 
  
   uid_t getuid(void);uid_t geteuid(void);
  
 
Getpwnam

Function Description

Get password file entry get password file entity

Header file and Declaration

#include 
 
  #include 
  
   struct passwd *getpwnam(const char *name);struct passwd *getpwuid(uid_t uid);int getpwnam_r(const char *name, struct passwd *pwd, char *buf, size_t buflen, struct passwd **result);int getpwuid_r(uid_t uid, struct passwd *pwd, char *buf, size_t buflen, struct passwd **result);
  
 
Setgid

Function Description

Set group identity sets the user group ID

Header file and Declaration

#include 
 
  #include 
  
   int setgid(gid_t gid);
  
 
Setuid

Function Description

Set user identity set user ID

Header file and Declaration

#include 
 
  #include 
  
   int setuid(uid_t uid);
  
 
Sigemptyset

Function Description

POSIX signal set operations.

Header file and Declaration

#include 
 
  int sigemptyset(sigset_t *set);int sigfillset(sigset_t *set);int sigaddset(sigset_t *set, int signum);int sigdelset(sigset_t *set, int signum);int sigismember(const sigset_t *set, int signum);
 
Setsid

Function Description

Creates a session and sets the process group ID

Header file and Declaration

#include 
 
  pid_t setsid(void);
 
Dup2

Function Description

Duplicate a file descriptor

Header file and Declaration

#include 
 
  int dup(int oldfd);int dup2(int oldfd, int newfd);#define _GNU_SOURCE#include 
  
   int dup3(int oldfd, int newfd, int flags);
  
 
Mlockall

Function Description

Lock and unlock memory

Header file and Declaration

#include 
 
  int mlock(const void *addr, size_t len);int munlock(const void *addr, size_t len);int mlockall(int flags);int munlockall(void);
 
Getenv

Function Description

Get an environment variable

Header file and Declaration

#include 
 
  char *getenv(const char *name);
 

Original article address: Introduction to the database functions of memcached source code reading. Thank you for sharing it with the original author.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.