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

  • Home
  • SEARCH
  • 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 7709071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:46:19+00:00 2026-06-01T00:46:19+00:00

I am trying to install a CTRL-Z (SIGTSTP) handler for a running foreground process.

  • 0

I am trying to install a CTRL-Z (SIGTSTP) handler for a running foreground process.

I set the handler (sigaction) right before I wait in the parent. Is this the right place? It doesn’t seem to work right..

EDIT:

I am writing a shell. Here is an outline of how my code looks like. I currently set the handler in the parent as shown below (which doesn’t seem to work).

// input from user for command to run
pid_t pid;
pid = fork();

// Child Process
if (pid == 0) {
    // handle child stuff here
    // exec() etc...
}

else if (pid < 0)
    // error stuff

/* Parent Here */
else {
    // Give process terminal access
    // SET HANDLER FOR SIGTSTP HERE???
    wait()
    // Restore terminal access
}
  • 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-01T00:46:21+00:00Added an answer on June 1, 2026 at 12:46 am

    You are doing things complete wrong.

    You DON’T send SIGTSTP to child process, the tty send SIGTSTP to child process DIRECTLY.

    Try

    $ stty -a
    speed 38400 baud; rows 55; columns 204; line = 0;
    intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
    -parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts
    -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8
    opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
    isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke
    

    Notice:

    susp = ^Z;
    

    that tells the tty how to deal with “CTRL-Z”, when the tty gets ^Z it sends SIGTSTP signal to all process in the current foreground process group

    How to handle process group

    When you launch a new process in the shell, before execvX, put the new process into a new process group, then call tcsetpgrp to set the new process group foreground. So any future signal will send to the child process directly. if the child forks new process, they will be in the same process group; so the entire process group will be suspended when ^Z is pressed.

    pid = fork()
    if (pid) {
      // parent
      setpgid(pid, pid); // put child into a new process group
      int status;
      wait(pid, &status, 0);
    } else {
      // child
      pid = getpid();
      setpgid(pid, pid);
      if (isatty(0)) tcsetpgrp(0, pid);
      if (isatty(1)) tcsetpgrp(1, pid);
      if (isatty(2)) tcsetpgrp(2, pid);
      execvX ...
    }
    

    Once any signal comes from tty causing child processes stop/term/exit your shell will return from wait, check status to know what happened to the child.

    Prevent your shell from stopping

    Your shell should mask SIGTSTP signal, because shell do not suspend. You do this at the beginning, when you start the shell. but don’t forget fork will derive sigmask, so you need to enable SIGTSTP after fork in the child process.

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

Sidebar

Related Questions

Trying to install Scrapy on Mac OSX 10.6 using this guide : When running
I am new to this, trying to install git on my VPS running on
Trying to install pear package and keep getting this strange error. Can you shed
trying to install gdata python library client,receiving following errors: running install running build running
I was trying to install bundler in Linux Mint. but I'm getting this error
I am trying install dataimport handler in solr 3.3 for connecting mysql db to
Trying to install this ipython version. infact there's a django-starter project which uses buildout
Trying to install mysql2 gem on ruby 1.9.2 and I get this error: Installing
Im trying to install recaptcha on a Rails3 app (Im using Passenger), this is
Trying to install Cython on a small VPS running Ubuntu Server. Did sudo apt-get

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.