小编How*_*ane的帖子

asprintf():如何释放指针?

我有这样的代码:我分配了两次日志,是否有第一个和日志的潜在内存泄漏?

char *log = NULL;
asprintf(&log, "Hello: %s", name);
if (known_person== true){
    asprintf(&log, "%s, %s", log, ", my old friend.");
}
free (log);
Run Code Online (Sandbox Code Playgroud)

c linux

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

Linux:性能最高,找不到内核符号

已编译并安装具有Linux-Next内核2015-06-04的Ubuntu 15.04。

然后启动该内核,然后运行perf top,但显示未找到符号。

如何在perf中手动加载内核符号?

root@ubuntu-server:/boot# uname -r
4.1.0-rc6.060402222+

root@ubuntu-server:/proc# ls kall*
kallsyms

root@ubuntu-server:/boot# ls | grep 4.1.0-rc6.060402222
config-4.1.0-rc6.060402222+
initrd.img-4.1.0-rc6.060402222+
System.map-4.1.0-rc6.060402222+
vmlinuz-4.1.0-rc6.060402222+

root@ubuntu-server:/# perf top
No kallsyms or vmlinux with build-id 438e4365574d514672888bcfdd6292dbcf71f38f was found
[kernel.kallsyms] with build id 438e4365574d514672888bcfdd6292dbcf71f38f not found, continuing without symbols
Warning:
A vmlinux file was not found.
Kernel samples will not be resolved.
^C

root@ubuntu-server:/proc# perf top -k /boot/vmlinuz-4.1.0-rc6.060402222+
Warning:
The /boot/vmlinuz-4.1.0-rc6.060402222+ file can't be used: Success
Kernel samples will not be resolved.
^C
Run Code Online (Sandbox Code Playgroud)

在Linux-next文件夹中,.config文件已启用内核调试:

CONFIG_DEBUG_KERNEL=y
Run Code Online (Sandbox Code Playgroud)

linux symbols linux-kernel perf

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

cscope:ctrl +']'不起作用

我刚刚安装了cscope-15.8b,然后转到linux-next文件夹,运行“ cscope -R”,构建标记后,然后通过“查找此文件”打开一个文件//到目前为止一切顺利。

现在,如果要通过ctrl+ 转到符号的定义,]它将抛出错误:“ E433:无标签文件”“ E426:未找到标签”。

如果我打开cscope.out文件,我会看到它看起来像坏了(见下文)。我该如何解决?

1 ^ B〜<¡dio.h>

2 ^ B〜<¡dlib.h>

3 ^ B〜

linux cscope

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

Linux C:重新定义包含标头的错误

我有一个项目,其下面的标题包括地图:

main.c <- main.h <- tcphelper.h <- tcptest.h <- util.h
                 <- udptest.h    <------------- util.h
Run Code Online (Sandbox Code Playgroud)

util.h中,我定义了struct cpu_usage的函数原型:

void get_cpu_usage(struct cpu_usage *cu);
Run Code Online (Sandbox Code Playgroud)

现在,当我通过GCC编译这个项目时,我有这个重定义错误.怎么解决这个问题?

谢谢!

In file included from udptest.h:15:0,
                 from main.h:10,
                 from main.c:7:
util.h:27:8: error: redefinition of struct cpu_usage
 struct cpu_usage{
        ^
In file included from tcptest.h:14:0,
                 from tcphelper.h:10,
                 from main.h:9,
                 from main.c:7:
util.h:27:8: note: originally defined here
 struct cpu_usage{
        ^
Run Code Online (Sandbox Code Playgroud)

c linux gcc compiler-errors

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

Linux,C,如何取消计时器?

我想创建一个计时器并将其设置为在60秒后仅触发一次。但是在60秒内触发之前,用户可以通过Ctrl + C取消应用程序。如何取消计时器并正常退出程序?

例如,对于保罗·格里菲斯(Paul Griffiths)对此线程的回答中的代码:信号处理程序停止C语言中的Timer

如果用户在间隔触发之前通过Ctrl + C停止应用程序,如何在signal_handler中取消计时器?

void signal_handler(int n)
{
    //Ctrl+C
    if (n == SIGINT){
        PRINT_ERR("Ctrl+C");
        **//how to cancel it_val here???**
    }
    exit (1);
}

bool timer_fired = false;
void TimerStop(int signum) {
    printf("Timer ran out! Stopping timer\n");
    timer_fired = true;
}

struct itimerval it_val;

void TimerSet(struct itimerval it_val, int interval) 
{
    printf("starting timer\n");

    it_val.it_value.tv_sec = interval;
    it_val.it_value.tv_usec = 0;
    it_val.it_interval.tv_sec = 0;
    it_val.it_interval.tv_usec = 0;

    if (signal(SIGALRM, TimerStop) == SIG_ERR) {
        perror("Unable to catch SIGALRM");
        exit(1); …
Run Code Online (Sandbox Code Playgroud)

c linux timer

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

Linux Bash:如果符合条件,则为行添加前缀

我有一个包含一些行的文件.

如果它包含一些关键词,我想为这些行添加前缀.

我怎么做?谢谢!

示例:

我想在行的开头添加"###"带" Hello"的行:

目前这个文件有:

This is the beginning.
Hello I am Simon.
This is a simple line;
Hello Mike.
This is another line.
Run Code Online (Sandbox Code Playgroud)

我想将此文件更改为:

This is the beginning.
###Hello I am Simon.
This is a simple line;
###Hello Mike.
This is another line.
Run Code Online (Sandbox Code Playgroud)

linux bash

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

Linux UDP Socket:为什么选择()?

我是Linux套接字编程的新手.我在这里有一个基本问题:

UDP,我们为什么需要select()

  1. UDP无状态一样,UDP服务器只处理它收到的任何数据.一旦新客户端发送数据,就不会创建新的套接字,对吗?

  2. 如果是这样,select()一旦此套接字有数据到达,将返回/通知.所以我们不需要全部检测吞吐量以检查通知哪个套接字(因为只有一个套接字);

  3. 这是真的?non-blocking UDP socket+ select()== blocking UDP socket.

谢谢!

sockets linux udp

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

标签 统计

linux ×7

c ×3

bash ×1

compiler-errors ×1

cscope ×1

gcc ×1

linux-kernel ×1

perf ×1

sockets ×1

symbols ×1

timer ×1

udp ×1