小编Nog*_*oga的帖子

如何在内核代码中获取子进程列表

我想到一个进程的子任务(进程)列表,这里是代码:

void myFunc()
{
    struct task_struct* current_task;
    struct task_struct* child_task;
    struct list_head children_list;      

    current_task = current;
    children_list = current_task->children;
    child_task = list_entry(&children_list,struct task_struct,tasks);
    printk("KERN_INFO I am parent: %d, my child is: %d \n",
            current_task->pid,child_task->pid);
}
Run Code Online (Sandbox Code Playgroud)

当前的pid是正确的,但是孩子的pid不正确.我究竟做错了什么?

c linked-list task linux-kernel

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

我怎么能确定在使用pause()时我没有丢失信号?

我正在编写一个程序,它使用fork来创建子进程,并在完成后对它们进行计数.我怎么能确定我没有丢失信号?如果孩子在主程序仍然处理前一个信号时发送信号,会发生什么?是"丢失"的信号?我怎么能避免这种情况?

void my_prog()
{
    for(i = 0; i<numberOfDirectChildrenGlobal; ++i) {    
        pid = fork();
        if(pid > 0)//parent
            //do parent thing
        else if(0 == pid) //child
            //do child thing
        else
            //exit with error
    }

    while(numberOfDirectChildrenGlobal > 0) {
        pause(); //waiting for signal as many times as number of direct children
    }

    kill(getppid(),SIGUSR1);
    exit(0);
}

void sigUsrHandler(int signum)
{
    //re-register to SIGUSR1
    signal(SIGUSR1, sigUsrHandler);
    //update number of children that finished
    --numberOfDirectChildrenGlobal;
}
Run Code Online (Sandbox Code Playgroud)

c linux signals

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

将对象添加到向量时编译器错误

将对象添加到向量时,为什么会出现以下编译器错误,该向量的数据成员是否引用了另一个对象?

编译错误:

错误1错误C2582:'产品'中的'operator ='功能不可用c:\ program files\microsoft visual studio 8\vc\include\xutility 2726

在程序中,我在创建新的Product对象之前收集所有数据,

然后,创建对象并将所有数据传递给构造函数:

问题出在push_back(p)行,

vector<Product> productsArr;
vector<string> categoriesArr;

class Product

{

private:
  string m_code;    
  string m_name;    
  string& m_category_ref;     
  string m_description;    
  double m_price;    
  Product();    
public:
  Product(const string& code,const string& name,string& refToCategory,   
  const string& description, const double& price):m_category_ref(refToCategory)    
  {    
    m_code = code;
    m_name = name;
    m_description = description;
    m_price = price;
  }

}

void addProduct()
{    
  string code,name,description;    
  double price;    
  int categoryIndex;    
  getProductData(code,name,price,categoryIndex,description);    
  Product p(code,name,categoriesArr[categoryIndex],description,price);    
  productsArr.push_back(p);    
}
Run Code Online (Sandbox Code Playgroud)

来自xutility的一行:

// TEMPLATE FUNCTION fill
template<class …
Run Code Online (Sandbox Code Playgroud)

c++ visual-studio

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

标签 统计

c ×2

c++ ×1

linked-list ×1

linux ×1

linux-kernel ×1

signals ×1

task ×1

visual-studio ×1