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 7816125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:45:09+00:00 2026-06-02T05:45:09+00:00

There is a simple program below that takes a HUP and continues with execv.

  • 0

There is a simple program below that takes a HUP and continues with execv. The problem is when the execv call is executed, after that the code continues from the places where the HUP comes.I want, after execv the code must exit from main and than start again from the beginning of main.

char* a;
char** args;

void hup_func(){
    printf("aaaa\n");
    if(execv(a,args))
        printf("bbb\n");
}

int main(int argc,char* argv[]){
    signal(SIGHUP,hup_func);
    args=argv;
    a=args[0];
    printf("%s\n",a);
    while(1){
        printf("test\n");
        sleep(10);
     }

   return 0;
}

The name of the program is deneme1. The output of the code is when I sent HUP;

./deneme1
test
test
aaa 
bbbb
test.

But I want it, when I sent HUP, it must start with the start of the main. like that

./deneme1
test
test
aaa
bbb
./deneme1
test
...

I want it to return at the beginning of the main after HUP, not the place where it was before

  • 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-06-02T05:45:10+00:00Added an answer on June 2, 2026 at 5:45 am

    You’re not sending the correct arguments to execv, and therefore the function is exiting with an error. So you’re simply exiting the signal handler rather than overlaying the process with a new copy of the process.

    The argument signature for execv is:

    int execv(const char *path, char *const argv[]); 
    

    The second argument should be an array of const pointers to char, with the last element being a NULL pointer. The char* a that you’re passing for the second argument is not the correct type.

    Finally, execv is not considered an asynchronous signal-safe function, where-as it’s sister-function, execve is. You should use the latter. The same is also true for any of the printf family of functions … if you need to write to the terminal, use write instead.

    Update: I re-ran your updated code. The program is restarting properly, but the problem is that the signal mask is being inherited from the original process that was overlaid by the call to execv. Since you are running execv from inside a signal-handler, the SIGHUP will be blocked in the overlaid process, and you won’t be able to send any other SIGHUP signals to the process. To undo this, you need to unblock the SIGHUP signal using sigprocmask() right after you assign your signal-handler using signal().

    For instance, change your main to:

    int main(int argc,char* argv[])
    {
        sigset_t signal_mask;
    
        signal(SIGHUP,hup_func);
    
        //unblock the SIGHUP signal if it's blocked
        sigaddset(&signal_mask, SIGHUP);
        sigprocmask(SIG_UNBLOCK, &signal_mask, NULL);
    
        args=argv;
        a=args[0];
        printf("%s\n",a);
        while(1){
            printf("test\n");
            sleep(10);
         }
    
       return 0;
    }
    

    I’ve compiled and run this on Ubuntu 12.04, and it now runs perfectly.

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

Sidebar

Related Questions

There is very simple task I want to do, that somehow makes the program
The code below plots some simple x-y data, but it has two problems that
i've made a simple program that change a string from lowercase to uppercase and
my program below is a simple windows form that searches for a file in
I'm writing a simple program. There is only one class in it. There is
There is a simple Client-Server program. The server is started $./server 5000 The client
In C#, is there a way to make a program that simply eats roughly
Are there simple libraries out there (.NET and Java) that are able to validate
There is simple cipher that translates number to series of . ( ) In
Is there a simple way to work with C++ objects directly from C? I

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.