小编mis*_*yes的帖子

python字符串中的单引号和双引号

我想调用一个python函数pexpect.spawn(cmd),其中cmd是一个字符串,如下所示:

ssh -t kity@192.199.61.205 'sudo nohup bash -c "./tcp_sender > /dev/null 2>&1 &"'
Run Code Online (Sandbox Code Playgroud)

IP地址总是在变化,所以它是这样的:

ssh -t kity@%s 'sudo nohup bash -c "./tcp_sender > /dev/null 2>&1 &"' %host_ip
Run Code Online (Sandbox Code Playgroud)

有几个'",我不知如何处理它所以基本上,它是关于如何处理在Python中逃逸,当有一个变量子,如何处理它

谢谢

python linux

2
推荐指数
1
解决办法
618
查看次数

如果我做任务但是在malloc之后没有memcpy会有什么后果吗?

在以下程序中:

int main()
{
  struct Node node;
  struct Node* p = (Struct Node*) malloc(sizeof(struct Node));
  *p =node;
  printf("%d\n", *p->seq);
}
Run Code Online (Sandbox Code Playgroud)

通常我做了 memcpy(p, node, sizeof(node))

现在我想上面的代码,并能正常工作,恐怕有任何后果或错误的东西,如果我做任务而不是memcpy之后malloc.有没有或任务是非常正确的?谢谢!

c malloc memcpy

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

如果我在同一个程序中创建了很多管道,会有什么后果吗?

我需要创建很多管道,我想在同一进程中的线程之间使用它们作为fifo队列,然后对它们进行选择/轮询.

我的问题是,如果我创建了很多队列,这会对程序的性能产生很大影响吗?管道数限制,资源消耗等

谢谢!

c linux pipe

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

在linux C中寻找位图实现API

我想在Linux C中使用位图API.

我需要2 ^ 18位,所以它需要32KB内存.我会经常在位图中设置和取消设置位.

所以基本上我需要API,如:

set_bitmap(int i)  // it sets the i-th bit to 1 in the bitmap
unset_bitmap(int i) // it sets the i-th bit to 0 in the bitmap
bitmap_t create_bitmap(int n) // it creates a bitmap of size n, like n=2^18
Run Code Online (Sandbox Code Playgroud)

有没有源代码或类似的源代码?

谢谢!

c linux api bitmap

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

使用shell脚本在文件中获取1行相同的字段

我有一个文件,内容如下:

onelab2.warsaw.rd.tp.pl    5
onelab3.warsaw.rd.tp.pl    5
lefthand.eecs.harvard.edu  7
righthand.eecs.harvard.edu 7
planetlab2.netlab.uky.edu  8
planet1.scs.cs.nyu.edu     9
planetx.scs.cs.nyu.edu     9
Run Code Online (Sandbox Code Playgroud)

所以对于每一行,有一个数字我想要每个数字的第一行,所以对于上面的内容,我想得到:

onelab2.warsaw.rd.tp.pl    5
lefthand.eecs.harvard.edu  7
planetlab2.netlab.uky.edu  8
planet1.scs.cs.nyu.edu     9
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?我希望shell脚本,awk,sed等.

linux shell awk sed

0
推荐指数
1
解决办法
150
查看次数

字符串和管道中的奇怪行为

我有一个程序:

    int main()
    {
      int* p_fd = (int*)malloc(2*sizeof(int));
      char buf[100];
      pipe(p_fd);
      write(p_fd[1],"hello", strlen("hello"));
      int n;
      n = read(p_fd[0],buf,100);
      //printf("n is: %d\n",n);                // this line is important!
      buf[n]="\0";                             // this line triggers warning?
      printf("%s\n",buf);
    }
Run Code Online (Sandbox Code Playgroud)

当我编辑这个文件时,我总是得到警告:

[esolve@kitty temp]$ gcc -o temp temp.c
temp.c: In function ‘main’:
temp.c:38:9: warning: assignment makes integer from pointer without a cast [enabled by default]
Run Code Online (Sandbox Code Playgroud)

如果没有这一行printf("n is: %d\n",n); ,结果是:

[esolve@kitty temp]$ ./temp
 hellon
Run Code Online (Sandbox Code Playgroud)

有了这一行,我得到了预期的结果:

    [esolve@kitty temp$ ./temp
    n is: 5
    hello
Run Code Online (Sandbox Code Playgroud)

为什么这条线如此重要?谢谢!

c string pipe

0
推荐指数
1
解决办法
66
查看次数

什么时候需要显式指针类型转换?

在C中,如果我有两种类型的指针:

typeB *q;
typeA *p; 
Run Code Online (Sandbox Code Playgroud)

在下面的int中,是否没有必要进行显式转换 (typeA *)

1    p= q       is fine, no need to use p = (typeA  *)q;

2    define: void func(typeA *p){}

     call:  func(q);  is fine, no need to use func((typeA  *)q)

3    p=malloc(sizeof(typeA));   is fine, no need to use p=(typeA  *)malloc(sizeof(typeA))
Run Code Online (Sandbox Code Playgroud)

另外,C++是否相同?

谢谢!

c c++ pointers casting

0
推荐指数
1
解决办法
2600
查看次数

标签 统计

c ×5

linux ×4

pipe ×2

api ×1

awk ×1

bitmap ×1

c++ ×1

casting ×1

malloc ×1

memcpy ×1

pointers ×1

python ×1

sed ×1

shell ×1

string ×1