Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 705367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:02:44+00:00 2026-05-14T04:02:44+00:00

I create a linked list dynamically and initialize the first node in main(), and

  • 0

I create a linked list dynamically and initialize the first node in main(), and I add to the list every time I spawn a worker process. Before the worker process exits, I print the list. Also, I print the list inside my sigchld signal handler.

in main():

head = NULL;
tail = NULL;
// linked list to keep track of worker process
dll_node_t *node;
node = (dll_node_t *) malloc(sizeof(dll_node_t)); // initialize list, allocate memory
append_node(node);
node->pid = mainPID; // the first node is the MAIN process
node->type = MAIN;

in a fork()’d process:

    // add to list
    dll_node_t *node;
    node = (dll_node_t *) malloc(sizeof(dll_node_t));
    append_node(node);
    node->pid = mmapFileWorkerStats->childPID;
    node->workerFileName = mmapFileWorkerStats->workerFileName;
    node->type = WORK;

functions:

void append_node(dll_node_t *nodeToAppend) {
    /*
     * append param node to end of list
     */

    // if the list is empty
    if (head == NULL) {
        // create the first/head node
        head = nodeToAppend;
        nodeToAppend->prev = NULL;
    } else {
        tail->next = nodeToAppend;
        nodeToAppend->prev = tail;
    }

    // fix the tail to point to the new node
    tail = nodeToAppend;
    nodeToAppend->next = NULL;
}

finally… the signal handler:

void chld_signalHandler() {
    dll_node_t *temp1 = head;
    while (temp1 != NULL) {
        printf("2. node's pid: %d\n", temp1->pid);
        temp1 = temp1->next;
    }

    int termChildPID = waitpid(-1, NULL, WNOHANG);
    dll_node_t *temp = head;
    while (temp != NULL) {
        if (temp->pid == termChildPID) {
            printf("found process: %d\n", temp->pid);
        }
        temp = temp->next;
    }
    return;
}

Is it true that upon the worker process exiting, the SIGCHLD signal handler is triggered? If so, that would mean that after I print the tree before exiting, the next thing I do is in the signal handler which is print the tree… which would mean i would print the tree twice?

But the tree isn’t the same. The node I add in the worker process doesn’t exist when I print in the signal handler or at the very end of main(). Any idea why?

Thanks,
Hristo

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T04:02:44+00:00Added an answer on May 14, 2026 at 4:02 am

    Presumably, you are calling fork() to spawn the worker process, and adding to the linked list in the child process.

    After you’ve called fork(), there are now two independent copies of your linked list – one belongs to the parent, and one belongs to the child. If the child adds a node, it’s adding it to its own linked list – the modification won’t be seen by the parent.

    You need to have the parent process add the node to its linked list.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create 2 linked list with a common intersection node. As I
I'm basically trying to create a linked list from a text file and add
#define STRLEN 65 /*Create linked list */ struct node { char str[STRLEN]; struct node
I am trying to create a linked list where you can enter items into
I would like to know how to create a linked list of linked lists.
What would be the best way to create a circularly linked list in C#.
So basically the assignment was we had to create a doubly linked list that's
Please explain what this task is about? Create a generic linked list class that
I need to create a Linked List from a text file that looks like
i wan to create a linked list that contains the name , age and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.