小编Laz*_*rus的帖子

同时启动所有线程

我无法理解pthread_mutex_lock/unlockpthread_cond_wait/等条件变量signal

我正在尝试创建 9 个threads,并让它们同时运行,以确定哪个是最有效的。

    int threadNumber = 0;
    pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
    pthread_cond_t cond = PTHREAD_COND_INITIALIZER;

    #define NUM_THREADS    9

    //used to store the information of each thread
    typedef struct{
        pthread_t  threadID;
        int policy;
        struct sched_param param;
        long startTime;
        long taskStartTime;
        long endTime1;
        long endTime2;
        long endTime3;
        long runTime;
        char startDate[30];
        char endDate[30];
    }ThreadInfo;

ThreadInfo myThreadInfo[NUM_THREADS];



//main function
int main(void){

   printf("running...\n");

   pthread_mutex_lock(&mutex); //lock the mutex//////
   pthread_cond_wait(&cond, &mutex); //start waiting//////


   int fifoPri = …
Run Code Online (Sandbox Code Playgroud)

c multithreading pthreads

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

c报告哪个信号终止了孩子

我已经非常广泛地研究了一个shell,现在我正在尝试升级这个代码来报告一个孩子被信号终止的时候(SIGINT除外).我也试图报告"核心转储"如果一个括号(类似bash)的发生.

   ...

   if(test == -1){ 
      cpid = fork();
      if(cpid < 0){
         //Fork wasn't successful 
         perror("fork");
         free(argList);
         return -1;
      }

      if(cpid == 0){
         //We are the child!
         close(pipefd[0]);
         dup2(pipefd[1], 1);

         execvp(args[0], args);         
         //execvp returned, wasn't successful
         perror("exec");
         fclose(stdin);  
         exit(127);
      }
      close(pipefd[1]);

      //Have the parent wait for child to complete, if flags allow 
      if(strcmp(flags, "NOWAIT") != 0){

         if(wait (&status) < 0){
            //Wait wasn't successful
            perror("wait");
         }
         else{


////////////////////////////////////////////////////////
        //report if a child has been terminated by a signal other than SIGINT
        if((WIFSTOPPED(status) …
Run Code Online (Sandbox Code Playgroud)

c fork signals

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

标签 统计

c ×2

fork ×1

multithreading ×1

pthreads ×1

signals ×1