Aborting the method, but continuing to execute the rest of the code

I want to run a section of my code, but with the option to interrupt it (ctrl-c) before it is fully completed, and resume execution of the rest of my code. (I work on the Linux platform.)

My guess is to create a fork, call a method, and then use signal processing. What steps are needed to process the signals?

void Manager::Run()
{
    pid_t pID = fork();

    if( pID<0 )
        exit(1);//give up here
    else if( pID==0 ) {            
        BuildList(); //I'd like the option to ctrl-c this only
        //some code here catch user signal interrupt?
    }
    else {;}

    waitpid(pID,NULL,0);//pause until BuildList() is done or interrupted


    PrintList();
}

It looks like I would like to use a string similar to a signal (SIGINT, sigint) somewhere in the if / else part. And I would need to define a function like this:

sigint(int param){ signal(param, SIG_DFL);};

In addition, I only want to kill the child process.

Is this the right idea to solve my problem? If so, what signal processing is needed to make this work?

UPDATE:
, , forking. , . , . .

Manager.hh

    static void sighandler(int signum)
    {
        PrintList();
        exit(1);
    };

.cc

void Manager::Run()
{
    signal(SIGINT,sighandler);//sets up sighandler()
    BuildList(); //add elements to a list
    signal(SIGINT,SIG_DFL);   //restore default 
    PrintList();  
}

sighandler , :
error: argument of type 'void (Manager::)(int)' does not match 'void (*)(int)'
signal(SIGINT,sighandler) :: (), .

PrintList() sighandler, :
error: cannot call member function 'void Manager::PrintList()' without object
PrintList(); sighandler().

, , PrintList() ( sighandler), .
error: invalid use of member 'Manager::theList' in static member function
error: invalid use of member 'Manager::it' in static member function

- ?

+3
2

, , .

, , , , . , .

+2

(, mmap), fork , . , , signal(SIGINT, SIG_IGN) ctrl-C ( fork), reset signal(SIGINT, SIG_DFL).

( ), : SIGINT , - ( SIGSEGV ). . . , BuildList(), .

SIGINT: - , , ctrl-C . , , (ctrl-\to send SIGQUIT ctrl-Z + kill).

+2

Source: https://habr.com/ru/post/1795101/