在我的linux机器上,如果我尝试复制/ proc/stat,则创建0字节文件.但如果我做cat/proc/stat它有数据.但大小始终显示为0.
cp /proc/stat statfile
Run Code Online (Sandbox Code Playgroud)
正在创建零字节文件.如果我写一个程序来复制,那么它是有效的.为什么会这样?
int main()
{
std::ifstream procFile("/proc/stat");
std::ofstream outfile("statfile");
char buf[1024];
while (!procFile.eof() && procFile.is_open())
{
procFile.getline(buf, 1024);
outfile << buf<<endl;
}
procFile.close();
outfile.close();
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我想自动化一项我经常执行的重复任务。这就是为不同的架构创建 rpm。要编译代码并创建 rpm,我需要设置项目环境。设置 env 后,我将为当前架构创建 rpm,并且我应该通过再次设置 env 为其他架构构建 rpm。
我正在尝试使这个过程自动化。问题是一旦设置了 env,我将成为新的 shell,因此我的脚本在子 shell 中不可见。如何自动化这个?
这就是我尝试过的。
cd $project_dir
setenv.sh x86 #creates new sub shell
make clean
make rpm
cp *rpm ~/
exit #exit from the sub shell
setenv.sh x86_64 #creates new shell
make clean
make rpm
cp *.rpm ~/
exit
Run Code Online (Sandbox Code Playgroud)
将 env 设置为 x86 后,接下来的命令不会被执行。
我想使用特定的 IP 地址运行 Prometheus。默认情况下,它在本地主机上运行。我在prometheus 配置中没有看到任何这样的选项
请检查以下代码,
import sys
try:
seq=eval(raw_input("Enter seq number: "))
if seq <= 0 or seq >= 9999:
print "Sequence number not in range [0001-9999]"
sys.exit(1)
except:
print "!!! Sequence number not in range [0001-9999]"
sys.exit(1)
Run Code Online (Sandbox Code Playgroud)
我给了一个字符串来eval raw_input运行.
$> python test.py
Enter seq number: "12"
Sequence number not in range [0001-9999]
!!! Sequence number not in range [0001-9999]
Run Code Online (Sandbox Code Playgroud)
为什么即使在接到exit电话后它也没有退出?
linux ×2
automation ×1
bash ×1
procfs ×1
prometheus ×1
python ×1
python-2.7 ×1
sh ×1
shell ×1
subshell ×1
unix ×1
xerces-c ×1