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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:20:16+00:00 2026-06-13T23:20:16+00:00

I current have a script that looks like this. # code mplayer $vid #

  • 0

I current have a script that looks like this.

# code

mplayer "$vid"

# more code

The problem is that if this script is killed the mplayer process lives. I wondering how I could make it so that killing the script would kill mplayer as well.

I can’t use exec because I need to run commands after mplayer.

exec mplayer "$vid"

The only possible solution I can think of is to spawn it in the background and wait until it finishes manually. That way I can get it’s PID and kill it when the script gets killed, not exactly elegant. I was wondering what the “proper” or best way of doing this is.

  • 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-13T23:20:16+00:00Added an answer on June 13, 2026 at 11:20 pm

    I was able to test the prctl idea I posted about in a comment and it seems to work. You will need to compile this:

    
    #include "sys/prctl.h"
    #include "stdlib.h"
    #include "string.h"
    #include "unistd.h"
    
    int main(int argc, char ** argv){
    
      prctl(PR_SET_PDEATHSIG, atoi(argv[1]),0,0,0);
    
      char * argv0 = strdup(argv[2]);
    
      char * slashptr = strrchr(argv0, '/');
      if(slashptr){
        argv0 = slashptr + 1;
      }
    
       return execvp(argv0, &(argv[2]));
    
    
    
    }
    
    

    Let’s say you have compiled the above to an executable named “prun” and it is in your path. Let’s say your script is called “foo.sh” and it is also in your path. Make a wrapper script that calls

    prun 15 foo.sh

    foo.sh should get SIGTERM when the wrapper script is terminated for any reason, even SIGKILL.

    Note: this is a linux only solution and the c source code presented is without detailed checking of arguments

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

Sidebar

Related Questions

Let's say I have a line of code that looks like this: setInterval(ajaxFunction,3000); where
I have a script that looks something like this: #!/usr/bin/env python # encoding: utf-8
I have an IronPython script that looks for current running processes using WMI. The
I have a MySQL Table that looks like this: The SQL to create the
I have data in an MYSQL database that looks like this: Project Date Time
I have a script that obtains information about the current folders and subfolders within
I have following script that executes all the .reg files in the current directory.
I have the strangest issue. I have a script that calculates what the current
I have the following script that successfully retrieves the current track and updates my
The code i current have is this. function update (){ latest_id = $('#image:first').data('position'); /*

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.