AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-254697

z.h.'s questions

Martin Hope
z.h.
Asked: 2021-10-09 05:59:50 +0800 CST

ssh 密钥的签名类型不可更改是否正确?

  • 0

使用 生成密钥对时ssh-keygen,可以通过 指定所需的签名类型-t,例如ssh-keygen -t ssh-rsa。我想知道,一旦创建了密钥对,ssh 私钥的签名类型是否不可更改?

如果可以更改,我可以使用哪个工具来更改签名类型?如何?

我问这个问题是因为我的一个旧密钥使用ssh-rsa签名类型,现在ssh-rsa签名算法已被弃用。

ssh
  • 2 个回答
  • 418 Views
Martin Hope
z.h.
Asked: 2019-05-15 00:35:05 +0800 CST

mmap - 映射到 2^48 以上的地址

  • 0

我知道 64 位 PC 使用的地址空间是[0,2^48),但是我可以使用 mmap 将文件映射到 2 48以上的地址吗?

我写了下面的代码,但发现映射的地址还在里面[0,2^48)。

int
main(void) {
    const char* name = "/tmp/file";

    int fd = open(name, O_RDONLY);
    if (fd < 0) {
        perror("open");
        exit(-1);
    }

    int pageSize = sysconf(_SC_PAGE_SIZE);
    void* targetAddr = (void*)(0UL - pageSize);

    char* str = mmap(targetAddr, pageSize, PROT_READ, MAP_SHARED, fd, 0);
    if (str == MAP_FAILED) {
        perror("mmap");
        exit(-1);
    }

    printf("addr: %p\n", str);

    return 0;
}

样本输出:addr: 0x7fc761f6f000

甚至可以将某些文件映射到 2 48以上的地址mmap吗?

如果没有,我该如何使用“未使用的”bit48-bit63?

我只是好奇如何利用地址的高位。

操作系统:Ubuntu16.04

内存大小:4GB

mmap
  • 1 个回答
  • 247 Views
Martin Hope
z.h.
Asked: 2019-05-06 00:55:54 +0800 CST

是什么导致 Make 删除中间文件?

  • 19

我写了一个Makefile,发现在执行命令时,在Mmakefile中的所有命令都执行完之后,执行make了一个意外。rm但是我没有rm在Makefile中写命令。

run-%: d/%.out
    $<

d/%.out: d/%.c
    gcc -o $(subst .c,.out,$<) $<

运行输出make run-a:

gcc -o d/a.out d/a.c
d/a.out
rm d/a.out

注意尾随rm d/a.out,我没有写。

什么情况下会添加自动rm命令?

make
  • 1 个回答
  • 4204 Views
Martin Hope
z.h.
Asked: 2019-03-23 02:49:23 +0800 CST

我的 makefile 关于通配符有问题

  • 1

我在目录中有一堆.c测试源文件tests/。现在我想分别编译和链接它们并将可执行文件输出*.out到tests/. 所以我写了一个makefile,没有用。

# ...
TestDir := tests
TestSourceFile := $(shell sh -c "ls tests/*.c")
TestTargetFile := $(subst .c,.out,$(TestSourceFile))

TestFrame := testframe.o

TestNeededObjectFile := $(TestFrame) \
    + util.o \
    + tokennames.o \
    + lex.yy.o \
    + hex.o \

.PHONY: test-%

test-%: $(TestDir)/%.out
    $^

.PHONY: test

test: $(TestTargetFile)
    @for t in $(TestTargetFile); do \
        $$t ; \
    done

$(TestDir)/%.out: $(TestDir)/%.o $(TestNeededObjectFile)
    gcc -o $@ $^

%.o : %.c
    gcc -c $(CFLAGS) $^

clean:
    rm -rf *.o lextest *.yy.? *.tab.? *.output $(TokenNameFile) \
        $(TestDir)/*.out

当我运行make test-add( add.cis in tests/) 时,我期待看到add.outintests/但出现错误:

> make test-add
make: *** No rule to make target 'tests/add.out', needed by 'test-add'.  Stop.

我想知道如何正确编写这个makefile以及为什么这个makefile是错误的。

linux make
  • 1 个回答
  • 1668 Views
Martin Hope
z.h.
Asked: 2019-01-07 00:06:09 +0800 CST

gdb-customize 命令,如何测试是否设置了变量?

  • 0

我正在使用 gdb 进行调试,需要定义一些辅助命令。基本上我希望我的自定义命令根据给定的参数数量以不同的方式运行。

所以我要测试是否$arg*给出,见下面的代码:

define pgdir

    set $pgdir = $arg0

    if ($arg1) {
        // show the corresponding PDE
    } else {
        // show the whole page directory
    }

end

是否可以测试变量是否为无效?

gdb
  • 3 个回答
  • 96 Views
Martin Hope
z.h.
Asked: 2018-08-26 16:43:54 +0800 CST

将标准输出 fd 传递给“读取”系统调用,但它仍然可以正常工作 [重复]

  • 0
这个问题在这里已经有了答案:
如何(以及为什么)使用 stderr 进行读写? (2 个回答)
标准流是否都在同一个文件(/dev/tty)上运行? (1 个回答)
4年前关闭。

我将1(stdout)/ 2(stderr) 传递给read系统调用,但它仍然可以正常工作。然后我将0(stdin) 传递给write系统调用并发现它也有效!

int main(int argc, char** argv){
    char buf[1024] = "abcdefghi\n";

    write(0, buf, 10);

    char readbuf[1024] = {0};
    // read(1, readbuf, 10); works too
    read(2, readbuf, 10);
    write(2, readbuf, 10);

    return 0;
}

输出:

abcdefghi
hey stdin  <-- I input this
hey stdin

很迷茫,我以为应该是错误。

实验:

然后我尝试重定向 fd 2。

$ ./a.out 2>/dev/null

这次读取和第二次写入都不是“可见的”。输出是

abcdefgi

那么stderr可以用于读取吗?

然后我关闭标准输出和标准错误并制作两个标准输入副本:

int main(int argc, char** argv){
    char buf[1024] = "abcdefghi\n";

    close(1);
    close(2);

    dup2(0, 1);
    dup2(0, 2);

    write(0, buf, 10);

    char redbuf[1024] = {0};
    read(2, redbuf, 10);
    write(2, redbuf, 10);

    return 0;
}

它再次起作用。

输出:

abcdefghi
hey stdin  <-- I input this
hey stdin

那么stdin可以用来写吗?

我在这里需要一些解释。

问题

我想知道:

为什么 stdout/stderr 可以用于读取?

为什么stdin可以用于写?

三个流(stdin,stdout,stderr)在内部是一个流吗?

如果不是,为什么我会得到这个结果?

file-descriptors system-calls
  • 2 个回答
  • 2181 Views
Martin Hope
z.h.
Asked: 2018-07-01 16:36:00 +0800 CST

桌面环境的 $PATH 环境变量与 shell 中的环境变量是否不同?

  • 1

我试图找到.desktopqtcreator 的文件,所以我写了这个:

$ for p in ${XDG_DATA_DIRS//:/ }; do
    grep -rni 'qtcreator' $p;
done

这是最相关的行:

/usr/share/app-install/desktop/qtcreator-plugin-ubuntu:ubuntusdk.desktop:2:X-AppInstall-Package=qtcreator-plugin-ubuntu
/usr/share/app-install/desktop/qtcreator-plugin-ubuntu:ubuntusdk.desktop:6:Exec=qtcreator %F
/usr/share/app-install/desktop/qtcreator-plugin-ubuntu:ubuntusdk.desktop:7:Icon=ubuntu-qtcreator
/usr/share/app-install/desktop/qtcreator:qtcreator.desktop:2:X-AppInstall-Package=qtcreator
/usr/share/app-install/desktop/qtcreator:qtcreator.desktop:6:Exec=qtcreator %F
/usr/share/app-install/desktop/qtcreator:qtcreator.desktop:7:Icon=QtProject-qtcreator
/usr/share/app-install/desktop/qhimdtransfer:qhimdtransfer.desktop:12:#Icon=qtcreator_logo_32

我认为这qtcreator:qtcreator.desktop是 QtCreator 的桌面条目,所以我打开它并找出:

[Desktop Entry]
X-AppInstall-Package=qtcreator
X-AppInstall-Popcon=292
X-AppInstall-Section=universe

Exec=qtcreator %F
Icon=QtProject-qtcreator
Type=Application
Terminal=false
Name=Qt Creator
GenericName=Integrated Development Environment
MimeType=text/x-c++src;text/x-c++hdr;text/x-xsrc;application/x-designer;application/vnd.nokia.qt.qmakeprofile;application/vnd.nokia.xml.qt.resource;
Categories=Qt;Development;IDE;
InitialPreference=9

X-Ubuntu-Gettext-Domain=app-install-data

qtcreator 不在 shell 的变量 $PATH 中。但我仍然可以在 gnome unity 中启动 QtCreator。

从我注意到的freedesktop-exec-variables

如果未提供完整路径,则在桌面环境使用的 $PATH 环境变量中查找可执行文件。

问题

桌面环境的 $PATH 环境变量与 shell 不同吗?

如果是这样,包含桌面环境的 $PATH 变量的配置文件在哪里?

qtcreator:qtcreator.desktop我安装了较新版本的 QtCreator,然后在桌面中启动 QtCreator,并在不更改文件的情况下找出它对较新版本的引用。我认为与qt的路径有关吗?

桌面环境:gnome

操作系统:ubuntu16.04

编辑

我遇到的实际问题与 $PATH 无关(请参阅我的回答)。Gilles 的答案实际上是“桌面环境的 $PATH 环境变量与 shell 中的环境变量是否不同?”的答案。所以我接受了它,以防有人和我有同样的疑问。

desktop qt
  • 2 个回答
  • 1672 Views
Martin Hope
z.h.
Asked: 2018-05-12 00:31:40 +0800 CST

带有管道和重定向的命令

  • 3

包含管道和输出重定向的命令的执行顺序是什么?

假设我们执行以下操作:

Charles@myzone:/tmp$ mkdir /tmp/testdir      
Charles@myzone:/tmp$ cd /tmp/testdir   
Charles@myzone:/tmp/testdir$ touch file1 file2  
Charles@myzone:/tmp/testdir$ ls | wc -l
2
Charles@myzone:/tmp/testdir$ ls | wc -l > ls_result
Charles@myzone:/tmp/testdir$ cat ls_result
3

我知道如果你这样做,ls > result那么result将包含它自己的名字,因为外壳会做类似的事情

1) 创建/打开名为result 2) 的 fd 为resultstdout 3) execls

我ls_result期望值 2,但它是 3。

问题

上面的命令是如何ls | wc -w > ls_result执行的?

是否相当于(ls | wc -w ) > ls_result?

一些相关信息的链接?(我查阅了 bash 手册)

shell pipe
  • 2 个回答
  • 1013 Views
Martin Hope
z.h.
Asked: 2018-05-07 17:24:21 +0800 CST

即使 /etc/rc.local 中存在无限循环,也可以正常启动

  • 1

我将一个带有无限循环的python脚本放入/etc/rc.local但机器成功启动,这让我感到困惑。

内容/etc/rc.local:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi

/home/pi/py/startsignal.py &
/home/pi/py/fan.py
touch /home/pi/thisisrun
exit 0

启动信号.py

#!/usr/bin/python
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)

GPIO.output(18, 1)

风扇.py

#!/usr/bin/python
# coding: utf8
import RPi.GPIO as gpio

gpio.setmode(gpio.BCM)
upper_temp = 55
lower_temp = 45
# minutes
check_interval = 2

def get_temp():
    with open('/sys/class/thermal/thermal_zone0/temp', 'r') as f:
        temp = float(f.read()) / 1000
    return temp

def check_temp():
    if get_temp() > upper_temp:
        gpio.setup(23, gpio.OUT)
    elif get_temp() < lower_temp:
        gpio.setup(23, gpio.IN)

if __name__ == '__main__':
    # check every 2 minutes
    try:
        while True:
            check_temp()
            sleep(check_interval * 60)
    finally:
        gpio.cleanup()

所有相关的代码都在上面。谷歌搜索后我想到了这个。

  1. 表示#!/bin/sh -e一旦发生错误脚本将退出。
  2. 文件没有创建,所以这/home/pi/thisisrun行上面一定有错误
  3. 启动到系统后,我可以看到它fan.py正在运行。所以我猜错误发生在fan.py. 但是fan.py里面有一个无限循环!

python脚本如何产生错误但仍然正常运行?

当永远不会返回时如何/bin/sh检测错误?fan.py

操作系统:树莓派拉伸

shell rc
  • 1 个回答
  • 1990 Views
Martin Hope
z.h.
Asked: 2018-05-06 23:27:01 +0800 CST

有组权限但无法创建文件

  • 9

我在玩 pi3B 时发现了一件奇怪的事情。我想在其中创建一个文件/sys/class/gpio(只是四处寻找,没有具体原因),但我得到一个Permission Denied。下面是一些信息。

pi@raspberrypi:/sys/class/gpio $ groups
pi adm dialout cdrom sudo audio video plugdev games users input netdev gpio i2c spi
pi@raspberrypi:/sys/class/gpio $ ls -ld .
drwxrwx--- 2 root gpio 0 May  6 00:28 .
pi@raspberrypi:/sys/class/gpio $ touch somefile
touch: cannot touch 'somefile': Permission denied

如您所见,我在组gpio中,该组具有 directory 的写权限/sys/class/gpio。

所以问题是/sys/class/gpio即使我所属的组具有权限,为什么我也无法在其中创建新文件。

在将pi用户添加到gpio组后,我尝试重新登录并重新启动,那是几天前的事了。

操作系统:树莓派拉伸

试过了newgrp 新组

permissions directory-structure
  • 1 个回答
  • 560 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve