小编luy*_*619的帖子

如何使用wget或其他工具在Linux中竞争性下载网站的子域?

我想下载http://source.yeeyan.org的所有文章。它有很多页面。例如,http://source.yeeyan.org/? page =22202 那么如何在Linux中使用wget或其他工具将其下载下来?目前,我使用以下参数,但是它不起作用。

wget --recursive --no-clobber --page-conditions --html-extension --convert-links --restrict-file-names = windows --domains yeeyan.org --no-parent source.yeeyan.org

linux wget download web-crawler

5
推荐指数
1
解决办法
2270
查看次数

golang中的原子操作是否建立了先发生的关系?

我知道可以发生g打印2然后给出以下代码0.

var a, b uint32

func f() {
    a = 1
    b = 2
}

func g() {
    fmt.Println(b)
    fmt.Println(a)
}

func main() {
    go f()
    g()
}
Run Code Online (Sandbox Code Playgroud)

如果我将所有读写更改为原子操作怎么办?是否保证如果g先打印2,那么还会打印1?

var a, b uint32

func f() {
    atomic.StoreUint32(&a, 1)
    atomic.StoreUint32(&b, 2)
}

func g() {
    fmt.Println(atomic.LoadUint32(&b))
    fmt.Println(atomic.LoadUint32(&a))
}

func main() {
    go f()
    g()
}
Run Code Online (Sandbox Code Playgroud)

memory concurrency atomic go

5
推荐指数
1
解决办法
407
查看次数

如何通过使用os.execv()在python中继承stdin和stdout

首先,我编写了一个c ++代码,如下所示:

#include <cstdio>
int main()
{
    int a,b;
    while(scanf("%d %d",&a,&b) == 2)
        printf("%d\n",a+b);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

g++ -o a a.cpp习惯于使它复杂化。

之后,我编写了如下的python代码:

import os,sys
sys.stdin = open("./data.in","r")
sys.stdout = open("./data.out","w")
pid = os.fork()
if pid == 0:
    cmd = ["./a","./a"]
    os.execv(cmd[0],cmd)
Run Code Online (Sandbox Code Playgroud)

但是,该data.out文件不包含任何内容。也就是说,子进程没有从其父进程继承stdin和stdout。但是当我编写如下的c ++代码时:

#include<unistd.h>
#include<cstdio>
int main()
{
    freopen("data.in","r",stdin);a
    freopen("data.out","w",stdout);
    int pid = fork();
    if(pid == 0)
    {
        char* cmd[]= {"./a","./a"};
        execv(cmd[0],cmd);
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我在中得到了正确的答案,data.out也就是说execv在c ++代码中有效。

那么,我该怎么做才能让execv也能在python中工作?我真的需要此功能才能工作,有人可以告诉我吗?非常感谢!

data.in 包含以下内容:

1 1
Run Code Online (Sandbox Code Playgroud)

python stdin fork stdout execv

3
推荐指数
1
解决办法
2619
查看次数

标签 统计

atomic ×1

concurrency ×1

download ×1

execv ×1

fork ×1

go ×1

linux ×1

memory ×1

python ×1

stdin ×1

stdout ×1

web-crawler ×1

wget ×1