深入redis内部之redis启动过程之一
redis作為一個服務器,它的啟動是從main函數開始的。redis.c
1. 進程重命名
#ifdef INIT_SETPROCTITLE_REPLACEMENTspt_init(argc, argv); #endif定義在config.h
/* Check if we can use setproctitle(). 修改進程名稱* BSD systems have support for it, we provide an implementation for* Linux and osx. */ #if (defined __NetBSD__ || defined __FreeBSD__ || defined __OpenBSD__) //bsd(unix的變種)宏定義 #define USE_SETPROCTITLE #endif#if (defined __linux || defined __APPLE__) //linux和蘋果的宏定義 #define USE_SETPROCTITLE #define INIT_SETPROCTITLE_REPLACEMENT void spt_init(int argc, char *argv[]); void setproctitle(const char *fmt, ...); #endifhttp://www.baike.com/wiki/BSD
BSD的開源後裔?
不同的BSD操作系統針對不同的用途及用戶,可應用于多種硬件構架。在政府機構中常能看到BSD的身影。雖然下面的BSD功能可能并非獨有,但每種BSD在各自的領域,都逐漸具有了良好聲譽,有的專注于性能,有的則以安全見長。
DragonflyBSD是最年輕的BSD,專門提供比FreeBSD更優秀的對稱多處理機系統,并使內核直接支持SSI集群,以取得更好的計算效果。這個項目在此方向上,才開始數年,主要關注i386平臺。?
FreeBSD在BSD家族中以易用性與高性能而著稱,由于主要用作微處理器架構,如i386、AMD's 64-bit i386擴展,所以FreeBSD非常關注多處理器。FreeBSD在i386和amd64服務器上,運行地非常好,當然,它也可以在其他硬件構架上運行。?
NetBSD擁有特別出色的可移植性,能在多達54種平臺上運行,小到嵌入式的掌上設備,大到服務器群,NetBSD甚至還在國際空間站中服務。
OpenBSD在密碼學和安全方面特別出眾,可移植性也很好,當然略遜于NetBSD。安全功能如OpenSSH,是由OpenBSD率先開創的。OpenBSD作為安全請求機器(security demanding machines)運行,受到好評。
必須注意的是,上面所羅列的,更多地是基于感性認識,并針對其開發焦點,并沒有嚴格地比較規則。實際而言,每種具體的BSD都可擔當許多角色任務。
2. 設置locale
?
setlocale(LC_COLLATE,"");http://manpages.ubuntu.com/manpages/lucid/en/man3/setlocale.3.html
NAME
setlocale - set the current localeSYNOPSIS
#include <locale.h>char *setlocale(int category, const char *locale);DESCRIPTION
The setlocale() function is used to set or query the program’s currentlocale.If locale is not NULL, the program’s current locale is modifiedaccording to the arguments. The argument category determines whichparts of the program’s current locale should be modified.LC_ALL for all of the locale.LC_COLLATEfor regular expression matching (it determines the meaning ofrange expressions and equivalence classes) and string collation.LC_CTYPEfor regular expression matching, character classification,conversion, case-sensitive comparison, and wide characterfunctions.LC_MESSAGESfor localizable natural-language messages.LC_MONETARYfor monetary formatting.LC_NUMERICfor number formatting (such as the decimal point and thethousands separator).LC_TIMEfor time and date formatting.The argument locale is a pointer to a character string containing therequired setting of category. Such a string is either a well-knownconstant like "C" or "da_DK" (see below), or an opaque string that wasreturned by another call of setlocale().If locale is "", each part of the locale that should be modified is setaccording to the environment variables. The details areimplementation-dependent. For glibc, first (regardless of category),the environment variable LC_ALL is inspected, next the environmentvariable with the same name as the category (LC_COLLATE, LC_CTYPE,LC_MESSAGES, LC_MONETARY, LC_NUMERIC, LC_TIME) and finally theenvironment variable LANG. The first existing environment variable isused. If its value is not a valid locale specification, the locale isunchanged, and setlocale() returns NULL.The locale "C" or "POSIX" is a portable locale; its LC_CTYPE partcorresponds to the 7-bit ASCII character set.A locale name is typically of the formlanguage[_territory][.codeset][@modifier], where language is an ISO 639language code, territory is an ISO 3166 country code, and codeset is acharacter set or encoding identifier like ISO-8859-1 or UTF-8. For alist of all supported locales, try "locale -a", cf. locale(1).If locale is NULL, the current locale is only queried, not modified.On startup of the main program, the portable "C" locale is selected asdefault. A program may be made portable to all locales by calling:setlocale(LC_ALL, "");after program initialization, by using the values returned from alocaleconv(3) call for locale-dependent information, by using themulti-byte and wide character functions for text processing ifMB_CUR_MAX > 1, and by using strcoll(3), wcscoll(3) or strxfrm(3),wcsxfrm(3) to compare strings.RETURN?VALUE
A successful call to setlocale() returns an opaque string thatcorresponds to the locale set. This string may be allocated in staticstorage. The string returned is such that a subsequent call with thatstring and its associated category will restore that part of theprocess’s locale. The return value is NULL if the request cannot behonored.CONFORMING?TO
C89, C99, POSIX.1-2001.NOTES
Linux (that is, glibc) supports the portable locales "C" and "POSIX".In the good old days there used to be support for the European Latin-1"ISO-8859-1" locale (e.g., in libc-4.5.21 and libc-4.6.27), and theRussian "KOI-8" (more precisely, "koi-8r") locale (e.g., inlibc-4.6.27), so that having an environment variableLC_CTYPE=ISO-8859-1 sufficed to make isprint(3) return the rightanswer. These days non-English speaking Europeans have to work a bitharder, and must install actual locale files.SEE?ALSO
locale(1), localedef(1), isalpha(3), localeconv(3), nl_langinfo(3),rpmatch(3), strcoll(3), strftime(3), charsets(7), locale(7)COLOPHON
This page is part of release 3.23 of the Linux man-pages project. Adescription of the project, and information about reporting bugs, canbe found at http://www.kernel.org/doc/man-pages/.?
轉載于:https://www.cnblogs.com/davidwang456/p/3539721.html
總結
以上是生活随笔為你收集整理的深入redis内部之redis启动过程之一的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Where Should an Arch
- 下一篇: 深入redis内部之redis启动过程之