Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,392
    • Issues 4,392
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 374
    • Merge Requests 374
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #10081

Closed
Open
Opened Feb 11, 2015 by nakal@trac-nakal

SIGTERM ignored when process has been detached from terminal

I've tried to write a simple Unix daemon that reacts to signals. Here is the reduced source code sample:

import Control.Concurrent
import Control.Monad
import System.Exit
import System.IO
import System.Posix.Signals

loop = forever $ threadDelay 1000000

main = do
        ppid <- myThreadId
        mapM (\sig -> installHandler sig (Catch $ trap ppid) Nothing)
                [ lostConnection, keyboardSignal, softwareTermination, openEndedPipe ]
        loop

trap tid = do
        hPutStrLn stderr "Signal received.\n"
        throwTo tid ExitSuccess

Such daemons usually run in background without a terminal attached. I verified that I can kill the process after being started on the terminal:

> ./daemon
Signal received.

With:

> killall daemon

in other terminal.

Other test, when I run it in background:

> ./daemon
(press Ctrl+Z)
> bg
> killall daemon
Signal received.

This case is also ok. Now the third test which is also OK:

> ./daemon > log 2>&1
(press Ctrl+Z)
> bg
> exit

In second terminal:

> cat log
> killall daemon
> cat log
Signal received.

> killall daemon
No matching processes belonging to you were found

Now the fourth test which is simply without a log file and this one fails:

> ./daemon
(press Ctrl+Z)
> bg
> exit

On some other terminal try to kill the process:

> killall xxx
> killall xxx
> killall xxx
> killall -9 xxx
> killall xxx
No matching processes belonging to you were found

Signal 9 (SIGKILL) kills the process hard without the signal trap. That's why it works, of course, but SIGTERM is being ignored for some reason. Maybe I am forgetting something, but in my opinion this should end the process properly, too.

Trac metadata
Trac field Value
Version 7.8.3
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component libraries/unix
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system FreeBSD
Architecture
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#10081