this post was submitted on 09 Feb 2024
29 points (91.4% liked)

Linux

48186 readers
1571 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

I'm trying to write a simple bash script that opens up GQRX, sends it some TCP commands, then closes it down.

Unfortunately, I've found that when I close the program like this, the next time it opens, it will pop up a window saying "crash detected" and ask me to review the configuration file. This prevents the app from loading unless someone is present to click the dialog box.

This error only seems to happen when I try to close the program using the bash script. Closing it by just clicking the X doesn't cause this problem next time it's launched.

I think I'm closing the app too aggressively which terminates it before it can wrap up its affairs, and it interprets this as a crash. What's the best way to close the app to keep this from happening?

I've tried:

  • pkill -3 gqrx
  • pkill -13 gqrx

But the problem persists. Is there an even softer way to close an application?

top 20 comments
sorted by: hot top controversial new old
[–] eager_eagle@lemmy.world 23 points 9 months ago (2 children)
[–] Helix@feddit.de 4 points 9 months ago

Would have been my suggestion as well.

[–] ch00f@lemmy.world 1 points 9 months ago
[–] just_another_person@lemmy.world 16 points 9 months ago

Read up on signals, and signal handling. Each number of signal sent has a different effect according to how they SHOULD be handled, but it's really.uo to the developer as to how they are actually handled when received by running code. Just learn the basic 5 levels you may need, and stick with those. Very few people (if anyone) has all of the different signals memorized, and most programs wouldn't handle each signal in a completely unique way.

[–] rufus@discuss.tchncs.de 11 points 9 months ago

could also try SIGTERM (15)

[–] mvirts@lemmy.world 8 points 9 months ago (2 children)

There's a setting called 'crashed' in the config that is set to false when the main window destructor is called https://github.com/gqrx-sdr/gqrx/blob/master/src/applications/gqrx/mainwindow.cpp

You may be able to copy a new config file to reset this variable after killing the app

[–] nyan@lemmy.cafe 3 points 9 months ago

Or sed the existing config file at the end of your script.

[–] ch00f@lemmy.world 3 points 9 months ago

Good find! This might be a good backup plan.

[–] mozz@mbin.grits.dev 7 points 9 months ago (1 children)

My first thought would be to use xdotool. Does that work for you?

[–] palordrolap@kbin.social 2 points 9 months ago (1 children)

This, or wmctrl that has some overlap. OR if this is Wayland (and not Xorg), whatever alternatives for those the window manager provides.

Anyone know what those are?

[–] mozz@mbin.grits.dev 2 points 9 months ago

Yeah agreed. All the people in here talking about signals... you're not, like, wrong, but you missed the nature of the question i.e. "hey it seems like this GUI application doesn't deal well with Unix signals, so what else can I do"

[–] Pantherina@feddit.de 3 points 9 months ago

The program will detect that it was closed via the SSD / CSD decorations (the three little buttons, one with the x) and handle the killing itself.

Maybe you can invoke that close command through the app?

[–] BCsven@lemmy.ca 1 points 9 months ago (2 children)

Closing from the X icon on the app window lets the program write out any info it needs to before shutdown. Killing the process from the terminal just ends the process totally

[–] rufus@discuss.tchncs.de 13 points 9 months ago* (last edited 9 months ago) (3 children)

That is not true. If you use SIGKILL (9) it ends the process totally. Other signals don't do that. And per default the cli commands don't send SIGKILL, but SIGTERM. It nicely asks the program to terminate and the program is supposed to write down it's data and do what it needs to do when signaled like that. You'd need to attach a '-9' to kill it without warning. (Even if the command is called 'kill'.)

[–] Max_P@lemmy.max-p.me 4 points 9 months ago (1 children)

A lot of GUI apps unfortunately don't catch SIGTERM, so it doesn't make much of a difference. A lot of them put their "exited normally" into the "the window was closed" handler.

For GQRX that might even be intentional, it's very unstable at times, and you do kill it pretty often. So they probably assume if it got SIGTERM, it was frozen and the WM offered the user to kill it and clicked yes.

[–] rufus@discuss.tchncs.de 1 points 9 months ago* (last edited 9 months ago) (1 children)

Sure, ~~if GUI apps don't handle it they just keep running. It's just asking them to terminate.~~ [Edit: I'll try that]

(We could just have a look at the code of GQRX in specific or just try it.)

[–] Max_P@lemmy.max-p.me 2 points 9 months ago

The default behaviour for SIGTERM (and most other signals) when unhandled is to terminate the process, so you might as well be sending SIGKILL. It won't keep running unless specifically coded to catch the signal and do nothing with it.

[–] BCsven@lemmy.ca 2 points 9 months ago* (last edited 9 months ago)

then it sounds like what is being killed has another child or parallel process that isn't getting killed by the command used. Or Sigterm 15 is needed for graceful shutdown of process

[–] atzanteol@sh.itjust.works 1 points 9 months ago

It's more than an "ask" - if it's not handled then the application will still shutdown. SIGTERM is "trapable" by the application though and should be used to safely terminate.

They'll also want to try SIGINT as that's what ctrl+c sends. The application may handle that one instead.

[–] 4am@lemm.ee 3 points 9 months ago

Only if you -9 it