小编San*_*raj的帖子

什么是运营商的理智?

Arity是运营商可以采用的操作数的数量.例如,+,-,*&是可同时用作一元(一个操作数)和二进制(两个操作数)的运算符.?:是唯一需要三个操作数的运算符(这就是它被称为三元运算符的原因).

但是,(逗号)运算符是什么?

c

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

捕获进程/退出的任何可能的解决方案?

我想捕获进程entry,exit并维护整个系统的日志(可能是守护进程).

一种方法是阅读/proc定期文件系统和维护列表,因为我没有看到注册可能性inotify/proc.此外,对于桌面应用程序,我可以得到帮助dbus,每当客户端注册到桌面时,我都可以捕获.

但对于非桌面应用程序,我不知道如何/proc定期继续阅读.

请提供建议.

c linux

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

如何强制ac程序在特定核心上运行

说我有以下c程序:

#include <stdio.h>

int main()
{
    printf("Hello world \n");
    getchar();

    return 0;
}

gcc 1.c -o helloworld
Run Code Online (Sandbox Code Playgroud)

并说,我有一个双核机器:

cat /proc/cpuinfo | grep processor | wc -l
Run Code Online (Sandbox Code Playgroud)

现在我的问题是,当我们执行程序时,我们如何强制该程序在core-0(或任何其他特定核心)中运行?

如何以编程方式执行此操作?例子,api,代码参考会有所帮助.

如果没有api可用,那么有没有编译时间,链接时间,加载时间这样做的方式?

OTOH,如何检查程序是在core-0还是core-1(或任何其他核心)中运行?

c process core

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

C中的字符串行为

我正在读C课程(这是荷兰语,所以可能你不会知道)并且有一个小练习来理解字符串行为.因此我创建了一个小的C程序来开始练习,但我的程序的第一个输出(对我来说)已经令人惊讶.

我的C程序的来源:

#include <string.h>
#include <stdio.h>

void printString(char *string)
{
    printf("0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19\n");
    printf("%c ",string[0]);
    printf("%c ",string[1]);
    printf("%c ",string[2]);
    printf("%c ",string[3]);
    printf("%c ",string[4]);
    printf("%c ",string[5]);
    printf("%c ",string[6]);
    printf("%c ",string[7]);
    printf("%c ",string[8]);
    printf("%c ",string[9]);
    printf("%c  ",string[10]);
    printf("%c  ",string[11]);
    printf("%c  ",string[12]);
    printf("%c  ",string[13]);
    printf("%c  ",string[14]);
    printf("%c  ",string[15]);
    printf("%c  ",string[16]);
    printf("%d  ",string[17]);
    printf("%d  ",string[18]);
    printf("%d\n",string[19]);
}

void main(){

    char str[20];

    strcpy(str,"Dag grootmoeder!");
    printString(str);
}
Run Code Online (Sandbox Code Playgroud)

我用gcc编译(没有特殊的开关)并且多次运行程序:(对于会说英语的人Dag …

c arrays string

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

"malloc(sizeof(struct a*))"和"malloc(sizeof(struct a))"是否相同?

这个问题是Malloc调用崩溃的延续,但在其他地方有效

我尝试了以下程序,我发现它工作(即没有崩溃 - 这也在上面提到的链接中提到).我很幸运能让它工作但是我正在寻找SO专家对于它为什么有效的合理解释?!

这里有一些关于memory使用malloc()wrt structures和.的分配的基本理解pointers

  • malloc(sizeof(struct a) * n)分配n类型struct a元素的数量.并且,可以使用a来存储和访问该存储器位置pointer-to-type-"struct a".基本上是一个struct a *.
  • malloc(sizeof(struct a *) * n)分配n类型struct a *元素的数量.然后,每个元素都可以指向类型的元素struct a.基本上malloc(sizeof(struct a *) * n)分配一个array(n-elements)-of-pointers-to-type-"struct a".并且,可以使用a来存储和访问分配的存储器位置pointer-to-(pointer-to-"struct a").基本上是一个struct a **.

所以当我们创造一个时array(n-elements)-of-pointers-to-type-"struct a",就是它

  1. 有效分配,struct a *而不是struct a **
  2. 有效访问/取消引用分配array(n-elements)-of-pointers-to-type-"struct a"使用 …

c struct pointers

5
推荐指数
2
解决办法
2万
查看次数

如何从守护程序在 KDE 中发送桌面通知

我有一个守护进程 ( netplugd),当我的电缆插入或拔出时,它可以执行一些操作。这些操作可以通过脚本定义bash。如何将通知(作为其他用户)发送到我的桌面(使用bash)以告知我有关电缆状态的信息。

我已经尝试过以下方法:

notify-sendknotify --passivepopup守护进程显示$DISPLAY尚未设置。

linux notifications kde4

5
推荐指数
2
解决办法
5503
查看次数

GDB中的格式化打印

我想做printf风格打印GDB.例如,我想打印一个变量值,但用一些文字来描述它是什么.可以这样做,如果是的话,你能举个例子吗?

c gdb

5
推荐指数
2
解决办法
5475
查看次数

NameError:未定义全局名称“create_engine”[尝试创建 SQLAlchemyJobStore 时]

我正在尝试添加一个SQLAlchemyJobStore作业存储(并使其成为default作业存储)并在其上存储一些作业。我正在运行mysql它有一个名为jobstore.

我有以下程序尝试向正在运行SQLAlchemyJobStoremysql数据库打开作业存储:

# sqlalchemy.py 
from sqlalchemy import *
from apscheduler.jobstores.sqlalchemy_store import SQLAlchemyJobStore
from apscheduler.scheduler import Scheduler
from datetime import datetime, timedelta
import time

def alarm(time):
    print('Alarm! This alarm was scheduled at %s.' % time)

_aps_config = {'standalone': 'True'}
_dbURL = 'mysql://root:<root-password>@localhost/jobstore'

if __name__ == '__main__':

    scheduler = Scheduler(_aps_config)
    scheduler.add_jobstore(SQLAlchemyJobStore(url=_dbURL), 'default')

    alarm_time = datetime.now() + timedelta(seconds=10)
    scheduler.add_date_job(alarm, alarm_time, name='alarm1', args=[datetime.now()])
    print 'alarms added: ', alarm_time

    alarm_time = datetime.now() + …
Run Code Online (Sandbox Code Playgroud)

python mysql sqlalchemy scheduler apscheduler

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

存储一组四个(或更多)值的最佳数据结构是什么?

说我有以下variables和它对应的values代表一个record.

name = 'abc'
age = 23
weight = 60
height = 174
Run Code Online (Sandbox Code Playgroud)

请注意,value可能是不同的types(string,integer,float,引用到任何-其他对象,等等).

会有很多records(至少> 100,000).当所有这四个(实际上是它们)组合在一起时,每一个都record将是.换句话说,存在没有与所有4 相同.uniquevariablesvaluesrecordvalues

我试图找到一个高效的数据结构,Python这将让我(商店)获取records基于其中任何一项variableslog(n)时间复杂度.

例如:

def retrieve(name=None,age=None,weight=None,height=None) 
    if name is not None and age is None and weight is None and height is None:
        /* get all records with the given name */ …
Run Code Online (Sandbox Code Playgroud)

python lookup logarithm data-structures

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

Git:无法重定向/解析'git fetch --dry-run'命令的输出

git fetch控制台上打印的命令输出消息有什么特别之处?我无法使用grep,xargs等等.也无法将输出重定向到文件..

注意:我正在使用git fetch --dry-run命令

[sangeeth@localhost santest-code]$ 
[sangeeth@localhost santest-code]$ git fetch --dry-run > /tmp/1
From ssh://git.code.sf.net/p/santest/code
   9f068d0..2b9dc4e  master     -> origin/master
[sangeeth@localhost santest-code]$ 
[sangeeth@localhost santest-code]$ cat /tmp/1              <= no data
[sangeeth@localhost santest-code]$  
[sangeeth@localhost santest-code]$ git fetch --dry-run | grep "ssh"     <= output has both lines
From ssh://git.code.sf.net/p/santest/code
   9f068d0..2b9dc4e  master     -> origin/master
[sangeeth@localhost santest-code]$ 
[sangeeth@localhost santest-code]$ git --version 
git version 1.7.11.4
[sangeeth@localhost santest-code]$ 
Run Code Online (Sandbox Code Playgroud)

我正在尝试解析git fetch --dry-run命令的输出以检查local(master)分支是否与remote(origin/master)分支是最新的.

git bash shell io-redirection

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