# Ctrl-C in script: atexit is ignored

**URL:** <https://discourse.julialang.org/t/ctrl-c-in-script-atexit-is-ignored/82413>\
**Category:** General Usage\
**Tags:** atexit\
**Created:** [June 8, 2022, 8:44am UTC](https://discourse.julialang.org/t/ctrl-c-in-script-atexit-is-ignored/82413 "2022-06-08T08:44:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mzaffalon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mzaffalon/32/214168_2.png) [@mzaffalon](https://discourse.julialang.org/u/mzaffalon)\
**Post date:** [June 8, 2022, 8:44am UTC](https://discourse.julialang.org/t/ctrl-c-in-script-atexit-is-ignored/82413/1 "2022-06-08T08:44:46Z")

</div>

I cannot seem to be able to use [atexit](https://docs.julialang.org/en/v1/base/base/#Base.atexit) properly, in the context of [catching Ctrl-C when running a script](https://docs.julialang.org/en/v1/manual/faq/#catch-ctrl-c) in Julia 1.7.2:

```julia
function main()
    atexit(() -> println("caught"))
    println("started program")
    sleep(5)
    println("done")
end

if abspath(PROGRAM_FILE) == @ __FILE__
    main()
end

```

Under Windows Terminal the output is

```julia
C:\Users\michele.zaffalon> julia script.jl
started program
# Ctrl-C pressed
C:\Users\michele.zaffalon>

```

and under git bash

```julia
$ julia script.jl
started program
# Ctrl-C pressed
Segmentation fault

```
