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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:09:21+00:00 2026-05-30T16:09:21+00:00

I am working on a game, so at one point I had to use

  • 0

I am working on a game, so at one point I had to use fork(), the main thread runs opengl graphics, and the child thread runs the game logic.

Now I have a problem. At some point, the user may press the ‘Exit’ button inside the game, which is handled by the secondary thread. Also, at some point the user may click the X button to exit the game which is handled by the main (glut) thread. So here is my question: how can I kill the other running thread, and exit?

Right now, if I close the window, the second thread keeps running, and if the second thread finishes, the first one keeps running.

Handling the ‘X’ button could be done using the atexit function, but I haven’t found a (safe) way of killing glutMainLoop().

  • 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-30T16:09:22+00:00Added an answer on May 30, 2026 at 4:09 pm

    If you are actually calling fork() (instead of starting a new thread) then you are actually creating another running process. When fork() is called, it returns a process-id to the parent process. That can be passed to kill() to kill the process. Under linux this looks like:

    #include <signal.h>
    
    pid_t pid = fork();
    if (pid == 0) {
       // you are in the child process
    } else if (pid > 0) {
       // you are in the parent process
       ...
       // send a termination signal
       kill(pid, SIGTERM);
    } else {
       // fork had an error which should be logged...
    }
    

    You need to choose what signal to send the process. SIGKILL (9) kills it hard for example.

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

Sidebar

Related Questions

Working on a game at work and at one point in the game the
I'm working on a 3D space trading game with some people, and one of
I'm working on this game titled Fortress, located at http://www.joemajewski.com/fortress . Anyways, it's one
I been working in a new game, and finally reached the point where I
I'm working on a simple 2D Real time strategy game using XNA. Right now
I've been trying to get this Sudoku game working, and I am still failing
I'm working on a game engine in C++ and I have methods like setColour
I'm working on a game that uses local area network. Like most of multiplayer
I am working on a game for iOS and I have to schedule an
Basic summary: Working on a game that generates a 15x15 grid for the player

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.