深入redis内部之redis启动过程之一
redis作為一個(gè)服務(wù)器,它的啟動(dòng)是從main函數(shù)開(kāi)始的。redis.c
1. 進(jìn)程重命名
#ifdef INIT_SETPROCTITLE_REPLACEMENTspt_init(argc, argv); #endif定義在config.h
/* Check if we can use setproctitle(). 修改進(jìn)程名稱(chēng)* 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和蘋(píng)果的宏定義 #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的開(kāi)源後裔?
不同的BSD操作系統(tǒng)針對(duì)不同的用途及用戶(hù),可應(yīng)用于多種硬件構(gòu)架。在政府機(jī)構(gòu)中常能看到BSD的身影。雖然下面的BSD功能可能并非獨(dú)有,但每種BSD在各自的領(lǐng)域,都逐漸具有了良好聲譽(yù),有的專(zhuān)注于性能,有的則以安全見(jiàn)長(zhǎng)。
DragonflyBSD是最年輕的BSD,專(zhuān)門(mén)提供比FreeBSD更優(yōu)秀的對(duì)稱(chēng)多處理機(jī)系統(tǒng),并使內(nèi)核直接支持SSI集群,以取得更好的計(jì)算效果。這個(gè)項(xiàng)目在此方向上,才開(kāi)始數(shù)年,主要關(guān)注i386平臺(tái)。?
FreeBSD在BSD家族中以易用性與高性能而著稱(chēng),由于主要用作微處理器架構(gòu),如i386、AMD's 64-bit i386擴(kuò)展,所以FreeBSD非常關(guān)注多處理器。FreeBSD在i386和amd64服務(wù)器上,運(yùn)行地非常好,當(dāng)然,它也可以在其他硬件構(gòu)架上運(yùn)行。?
NetBSD擁有特別出色的可移植性,能在多達(dá)54種平臺(tái)上運(yùn)行,小到嵌入式的掌上設(shè)備,大到服務(wù)器群,NetBSD甚至還在國(guó)際空間站中服務(wù)。
OpenBSD在密碼學(xué)和安全方面特別出眾,可移植性也很好,當(dāng)然略遜于NetBSD。安全功能如OpenSSH,是由OpenBSD率先開(kāi)創(chuàng)的。OpenBSD作為安全請(qǐng)求機(jī)器(security demanding machines)運(yùn)行,受到好評(píng)。
必須注意的是,上面所羅列的,更多地是基于感性認(rèn)識(shí),并針對(duì)其開(kāi)發(fā)焦點(diǎn),并沒(méi)有嚴(yán)格地比較規(guī)則。實(shí)際而言,每種具體的BSD都可擔(dān)當(dāng)許多角色任務(wù)。
2. 設(shè)置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/.?
轉(zhuǎn)載于:https://www.cnblogs.com/davidwang456/p/3539721.html
總結(jié)
以上是生活随笔為你收集整理的深入redis内部之redis启动过程之一的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Where Should an Arch
- 下一篇: 深入redis内部之redis启动过程之