网上能查到一些,但很多都没有讲清楚怎么获取stat里头的mode以及怎么只修改其中的一个位
做法如下:
import stat
f_mode = os.stat(rndc_key_file).st_mode
logging.info("stat mode of rndc key file:%o, after or:%o", stat.S_IMODE(f_mode), stat.S_IMODE(f_mode)|stat.S_IROTH)os.chmod(rndc_key_file, stat.S_IROTH|stat.S_IMODE(f_mode))
@echo off rem Licensed to the Apache Software Foundation (ASF) under one or more rem contributor license agreements. See the NOTICE file distributed with rem this work for additional information regarding copyright ownership. rem The ASF licenses this file to You under the Apache License, Version 2.0 rem (the "License"); you may not use this file except in compliance with rem the License. You may obtain a copy of the License at rem rem http://www.apache.org/licenses/LICENSE-2.0 rem rem Unless required by applicable law or agreed to in writing, software rem distributed under the License is distributed on an "AS IS" BASIS, rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. rem See the License for the specific language governing permissions and rem limitations under the License. if "%OS%" == "Windows_NT" setlocal rem --------------------------------------------------------------------------- rem Start/Stop Script for the CATALINA Server rem rem Environment Variable Prerequisites rem rem Do not set the variables in this script. Instead put them into a script rem setenv.bat in CATALINA_BASE/bin to keep your customizations separate. rem rem CATALINA_HOME May point at your Catalina "build" directory. rem rem CATALINA_BASE (Optional) Base directory for resolving dynamic portions rem of a Catalina installation. If not present, resolves to rem the same directory that CATALINA_HOME points to. rem rem CATALINA_OPTS (Optional) Java runtime options used when the "start", rem "run" or "debug" command is executed. rem Include here and not in JAVA_OPTS all options, that should rem only be used by Tomcat itself, not by the stop process, rem the version command etc. rem Examples are heap size, GC logging, JMX ports etc. rem rem CATALINA_TMPDIR (Optional) Directory path location of temporary directory rem the JVM should use (java.io.tmpdir). Defaults to rem %CATALINA_BASE%\temp. rem rem JAVA_HOME Must point at your Java Development Kit installation. rem Required to run the with the "debug" argument. rem rem JRE_HOME Must point at your Java Runtime installation. rem Defaults to JAVA_HOME if empty. If JRE_HOME and JAVA_HOME rem are both set, JRE_HOME is used. rem rem JAVA_OPTS (Optional) Java runtime options used when any command rem is executed. rem Include here and not in CATALINA_OPTS all options, that rem should be used by Tomcat and also by the stop process, rem the version command etc. rem Most options should go into CATALINA_OPTS. rem rem JAVA_ENDORSED_DIRS (Optional) Lists of of semi-colon separated directories rem containing some jars in order to allow replacement of APIs rem created outside of the JCP (i.e. DOM and SAX from W3C). rem It can also be used to update the XML parser implementation. rem Defaults to $CATALINA_HOME/endorsed. rem rem JPDA_TRANSPORT (Optional) JPDA transport used when the "jpda start" rem command is executed. The default is "dt_socket". rem rem JPDA_ADDRESS (Optional) Java runtime options used when the "jpda start" rem command is executed. The default is 8000. rem rem JPDA_SUSPEND (Optional) Java runtime options used when the "jpda start" rem command is executed. Specifies whether JVM should suspend rem execution immediately after startup. Default is "n". rem rem JPDA_OPTS (Optional) Java runtime options used when the "jpda start" rem command is executed. If used, JPDA_TRANSPORT, JPDA_ADDRESS, rem and JPDA_SUSPEND are ignored. Thus, all required jpda rem options MUST be specified. The default is: rem rem -agentlib:jdwp=transport=%JPDA_TRANSPORT%, rem address=%JPDA_ADDRESS%,server=y,suspend=%JPDA_SUSPEND% rem rem LOGGING_CONFIG (Optional) Override Tomcat's logging config file rem Example (all one line) rem set LOGGING_CONFIG="-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties" rem rem LOGGING_MANAGER (Optional) Override Tomcat's logging manager rem Example (all one line) rem set LOGGING_MANAGER="-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager" rem rem TITLE (Optional) Specify the title of Tomcat window. The default rem TITLE is Tomcat if it's not specified. rem Example (all one line) rem set TITLE=Tomcat.Cluster#1.Server#1 [%DATE% %TIME%] rem rem rem rem $Id: catalina.bat 1344732 2012-05-31 14:08:02Z kkolinko $ rem --------------------------------------------------------------------------- rem Suppress Terminate batch job on CTRL+C if not ""%1"" == ""run"" goto mainEntry if "%TEMP%" == "" goto mainEntry if exist "%TEMP%\%~nx0.run" goto mainEntry echo Y>"%TEMP%\%~nx0.run" if not exist "%TEMP%\%~nx0.run" goto mainEntry echo Y>"%TEMP%\%~nx0.Y" call "%~f0" %* <"%TEMP%\%~nx0.Y" rem Use provided errorlevel set RETVAL=%ERRORLEVEL% del /Q "%TEMP%\%~nx0.Y" >NUL 2>&1 exit /B %RETVAL% :mainEntry del /Q "%TEMP%\%~nx0.run" >NUL 2>&1 rem Guess CATALINA_HOME if not defined set "CURRENT_DIR=%cd%" if not "%CATALINA_HOME%" == "" goto gotHome set "CATALINA_HOME=%CURRENT_DIR%" if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome cd .. set "CATALINA_HOME=%cd%" cd "%CURRENT_DIR%" :gotHome if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome echo The CATALINA_HOME environment variable is not defined correctly echo This environment variable is needed to run this program goto end :okHome rem Copy CATALINA_BASE from CATALINA_HOME if not defined if not "%CATALINA_BASE%" == "" goto gotBase set "CATALINA_BASE=%CATALINA_HOME%" :gotBase rem Ensure that any user defined CLASSPATH variables are not used on startup, rem but allow them to be specified in setenv.bat, in rare case when it is needed. set CLASSPATH= rem Get standard environment variables if not exist "%CATALINA_BASE%\bin\setenv.bat" goto checkSetenvHome call "%CATALINA_BASE%\bin\setenv.bat" goto setenvDone :checkSetenvHome if exist "%CATALINA_HOME%\bin\setenv.bat" call "%CATALINA_HOME%\bin\setenv.bat" :setenvDone rem Get standard Java environment variables if exist "%CATALINA_HOME%\bin\setclasspath.bat" goto okSetclasspath echo Cannot find "%CATALINA_HOME%\bin\setclasspath.bat" echo This file is needed to run this program goto end :okSetclasspath call "%CATALINA_HOME%\bin\setclasspath.bat" %1 if errorlevel 1 goto end rem Add on extra jar file to CLASSPATH rem Note that there are no quotes as we do not want to introduce random rem quotes into the CLASSPATH if "%CLASSPATH%" == "" goto emptyClasspath set "CLASSPATH=%CLASSPATH%;" :emptyClasspath set "CLASSPATH=%CLASSPATH%%CATALINA_HOME%\bin\bootstrap.jar" if not "%CATALINA_TMPDIR%" == "" goto gotTmpdir set "CATALINA_TMPDIR=%CATALINA_BASE%\temp" :gotTmpdir rem Add tomcat-juli.jar to classpath rem tomcat-juli.jar can be over-ridden per instance if not exist "%CATALINA_BASE%\bin\tomcat-juli.jar" goto juliClasspathHome set "CLASSPATH=%CLASSPATH%;%CATALINA_BASE%\bin\tomcat-juli.jar" goto juliClasspathDone :juliClasspathHome set "CLASSPATH=%CLASSPATH%;%CATALINA_HOME%\bin\tomcat-juli.jar" :juliClasspathDone if not "%LOGGING_CONFIG%" == "" goto noJuliConfig set LOGGING_CONFIG=-Dnop if not exist "%CATALINA_BASE%\conf\logging.properties" goto noJuliConfig set LOGGING_CONFIG=-Djava.util.logging.config.file="%CATALINA_BASE%\conf\logging.properties" :noJuliConfig set JAVA_OPTS=%JAVA_OPTS% %LOGGING_CONFIG% if not "%LOGGING_MANAGER%" == "" goto noJuliManager set LOGGING_MANAGER=-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager :noJuliManager set JAVA_OPTS=%JAVA_OPTS% %LOGGING_MANAGER% rem ----- Execute The Requested Command --------------------------------------- echo Using CATALINA_BASE: "%CATALINA_BASE%" echo Using CATALINA_HOME: "%CATALINA_HOME%" echo Using CATALINA_TMPDIR: "%CATALINA_TMPDIR%" if ""%1"" == ""debug"" goto use_jdk echo Using JRE_HOME: "%JRE_HOME%" goto java_dir_displayed :use_jdk echo Using JAVA_HOME: "%JAVA_HOME%" :java_dir_displayed echo Using CLASSPATH: "%CLASSPATH%" set _EXECJAVA=%_RUNJAVA% set MAINCLASS=org.apache.catalina.startup.Bootstrap set ACTION=start set SECURITY_POLICY_FILE= set DEBUG_OPTS= set JPDA= if not ""%1"" == ""jpda"" goto noJpda set JPDA=jpda if not "%JPDA_TRANSPORT%" == "" goto gotJpdaTransport set JPDA_TRANSPORT=dt_socket :gotJpdaTransport if not "%JPDA_ADDRESS%" == "" goto gotJpdaAddress set JPDA_ADDRESS=8000 :gotJpdaAddress if not "%JPDA_SUSPEND%" == "" goto gotJpdaSuspend set JPDA_SUSPEND=n :gotJpdaSuspend if not &qu
最近去了几家公司面试,有一些大公司(比如企鹅)的考核内容真心弱智,考的都是些算法,尼玛,拿一个刚毕业的学生来做说不定也可以过的,看来本来就不是在招搞服务器的,举个例子,企鹅多个部门都曾出的一道题:如何知道集合A,B中的相关性。
意思就是哪些元素在A,B之中都有,哪些元素在A,B中不都出现。
其实解法很简单,学过算法的完全可以做到 。我们知道集合具有互异性,就是集合中的元素只能出现一次,可以建一个map< key, value >,是标准库的还是自建一个红黑树都无所谓,
将A,B集合中的元素当成key,各自遍历一次,插入map中,每次插入 value自增一次,最后再遍历一次map,所有 value = 2的key是A,B共有的,value=1的key是A,B相异的。
如果A,B中的元素是整数,而且很小,问题则退化成类似计数排序,解法如下:
#define MAX_NUM
A{ 2,4,6,10,7,25 } B{ 3,9,4,2,19,25 }
int test( int A[], int a_len, int B[], int b_len )
{
int size, i, max, tp_key;
int *tmp;
if( !a_len || !b_len )
{
return -1;
}
size = MAX_NUM * sizeof( int );
tmp = malloc( size );
if( !tmp )
{
return -1;
}
memset( tmp, 0, size );
max = 0;
for( i = 0; i < a_len; ++i )
{
tp_key = A[i];
max = tp_key > max ? tp_key : max;
tmp[ tp_key ]++;
}
for( i = 0; i < b_len; ++i )
{
tp_key = B[i];
max = tp_key > max ? tp_key : max;
tmp[ tp_key ] ++;
}
++max;
for( i = 0; i < max; ++i )
{
if( !tmp[ i ] )
continue;
if( 1 == tmp[ i ] )
{
printf( "%d is in A or B\n", i );
}
else
{
printf( "%d is in A and B\n", i );
}
}
free( tmp );
return 0;
}
言归正传,其实算法应该是大家的基本功,考核算法应该也没有错,但既然招的是服务器架构开发,我想考核更多的是实战经验。
有一家中等公司的面试题不错,此系列博文将围绕它展开研究。
原题:时间同步系统开发需求
需求场景:客户端向服务器发起登录请求,鉴权通过后(为了简化工作,所有登录请求,只要请求参数里的用户名和密码不为空,都鉴权通过),客户端再向服务器请求当前系统时间,服务器返回当前系统时间后关闭连接。
要求:
1、传输层使用TCP协议,应用层协议不限。
2、可支持同时在线用户量:大于 2W。
3、并发性能:没有明确指标。
4、服务器端运行环境:linux 2.4以上内核版本;开发语言:C++/C。
5、客户端运行环境:不限;开发语言:不限。(可以很简单,不要求界面)
6、要求有模拟性能测试操作方法,如多客户端、多线程模拟同时请求等。
7、用真实代码。
8、不要求日志系统,但是要考虑在主线程打印屏幕引起的性能问题。
我就觉得要是哪个公司面试的时候能出得出这样的题目,那就应该很专业了,对面试的人也就可以算得上挑战了。
tcp 服务端-客户端通信的程序,网上一搜一大堆,大家可能都会写,但是并发量和容错性不一定能上得去,2W的并发量不是盖出来的,如果这道题目能够搞定,基本上服务器这块应该是难不倒了。
下面说说我应该怎么做:
首先是建立前后端的通信协议:
request:
username/password, 约定username与password 各占32个字节(联同末位0)
response:
time_t 格式
由于通信内容简单,选择二进制传输,而不选择http,当然如果要考考 http 协议的了解,那就另当别论了。
不忙写程序,再对题目好好看看,因为我打算连载,请关注啦,呵呵。
下篇我给大家写客户端程序先。