How to keep programs open through a reboot?

Questions about other topics - please check if your question fits better in another category before posting here
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
User avatar
jimallyn
Level 19
Level 19
Posts: 9075
Joined: Thu Jun 05, 2014 7:34 pm
Location: Wenatchee, WA USA

How to keep programs open through a reboot?

Post by jimallyn »

I only rarely reboot my computer, usually only when I install a new kernel. But it would be great if all the programs I had running could be restarted automatically with the reboot. Any way to do that? I know I can put programs on auto-run at boot, but that's not exactly what I want. Not necessarily the same programs every time, just whatever I had running when I shut down. Any ideas?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
“If the government were coming for your TVs and cars, then you'd be upset. But, as it is, they're only coming for your sons.” - Daniel Berrigan
gittiest personITW
Level 12
Level 12
Posts: 4285
Joined: Tue May 28, 2019 4:27 pm

Re: How to keep programs open through a reboot?

Post by gittiest personITW »

A hibernation that can be activated through a new boot?
The first easy part might be this:
https://www.fosslinux.com/45454/enable- ... x-mint.htm

Edit:
Would it be possible to hibernate, then shutdown using the power button.
Someone versed in these things might be able to suggest a script to run in GRUB to access the hibernate file at boot?
User avatar
karlchen
Level 23
Level 23
Posts: 18209
Joined: Sat Dec 31, 2011 7:21 am
Location: Germany

Re: How to keep programs open through a reboot?

Post by karlchen »

Hi, Jimallyn.

The answer to your request depends on the desktop environment, which you use.
Cinnamon does not permit to save the list of running applications before logging off, so that the same applications will be launched after next login.
xfce has got an option in the logoff / reboot / shutdown dialogue box: Save session for future logins
I am not sure whether Mate has got the same feature, sorry. (No more Mate here.)

In brief:
For all desktop environments, which do not have the same option as xfce, Save session for future logins, the only workaround may be hibernation, as suggested by gittiest personITW.

Best regards,
Karl
Image
The people of Alderaan have been bravely fighting back the clone warriors sent out by the unscrupulous Sith Lord Palpatine for 771 days now.
Lifeline
Hoser Rob
Level 20
Level 20
Posts: 11796
Joined: Sat Dec 15, 2012 8:57 am

Re: How to keep programs open through a reboot?

Post by Hoser Rob »

karlchen wrote: Wed Jun 16, 2021 7:54 am ... Cinnamon does not permit to save the list of running applications before logging off, so that the same applications will be launched after next login....
Pretty sad for a "full featured" DE. Even Xfce will do that.
For every complex problem there is an answer that is clear, simple, and wrong - H. L. Mencken
gittiest personITW
Level 12
Level 12
Posts: 4285
Joined: Tue May 28, 2019 4:27 pm

Re: How to keep programs open through a reboot?

Post by gittiest personITW »

Or,
This will create a txt file of running programs cycled every 10 seconds so it doesn't get too large. (I wish I could take the credit for this but I found it on these forums).

Code: Select all

while true; do top -b -n 1 -w 256 | head -n 20 >> top-results.txt; sleep 10; done
Then, would it be possible to parse this file to run these programs on startup?
Again, someone who is versed in the dark arts might be able to help with this.
This is assuming that you don't have to start where you left off whereas the hibernation would be if you need to start where you left off.

Edit:
Could this txt file be appended to a startup script?
Just ideas, no knowledge about the cogs.
User avatar
karlchen
Level 23
Level 23
Posts: 18209
Joined: Sat Dec 31, 2011 7:21 am
Location: Germany

Re: How to keep programs open through a reboot?

Post by karlchen »

Hello, gittiest personITW.

I have my doubts, that your top loop will identify the applications, which I have started from the Mint application menu and which are still open, when I log off. Because only those should be restarted after the next login to the GUI.

I am afraid your top loop will write a long list of process names to the file, most of which will be background processes, which the OS will start up anyway. Apart from the fact that top does not display the commandline, which had been executed in order to start up a process.

Let me try your command in order to verify its resuling file.

--Added--
First of all, the command executes the loop endlessly.
This is waste of energy, because we are interested in the running user applications only, which the user has started from the application menu or maybe from the bottom panel, and which are still running at the point in time when the user clicks Logoff / Restart / Shutdown.
Second, look at the resulting file yourself. Not usable to restore the user session after next login.
Nice idea, but sorry, not usable.
In case the task were so trivial, then Cinnamon would very likely have it as well. But in fact, it has been removed from Cinnamon, because it did not work reliably. - Finding out how the xfce does it and adopt the idea might be a promising approach, even if it means that the wheel has been invented by others. :wink:

Cheers,
Karl
--
P.S.: Had to gzip the file, because the forum software considered 22 KB of .txt file too large. Hm.
Attachments
top-results.txt.gz
(2.37 KiB) Downloaded 37 times
Image
The people of Alderaan have been bravely fighting back the clone warriors sent out by the unscrupulous Sith Lord Palpatine for 771 days now.
Lifeline
gittiest personITW
Level 12
Level 12
Posts: 4285
Joined: Tue May 28, 2019 4:27 pm

Re: How to keep programs open through a reboot?

Post by gittiest personITW »

Hi Karlchen (nice cat),
I agree that it shouldn't just be run willynilly.

It would need at least an "ignore this line if process is already running" line stuck in there (technical term).

Actually - thinking more about this - it probably wouldn't be very stable even if you could get it to run. Some processes would have to be started in a specific order.
User avatar
karlchen
Level 23
Level 23
Posts: 18209
Joined: Sat Dec 31, 2011 7:21 am
Location: Germany

Re: How to keep programs open through a reboot?

Post by karlchen »

Hi, gittiest personITW.

See my update in the post above, starting with "--Added--". It is not so trivial. And top is the wrong command. To sum it up.
I have to admit that at the moment, I can only confirm what will not work, but have no better idea than maybe "forking" what already exists in xfce.

Cheers,
Karl
Image
The people of Alderaan have been bravely fighting back the clone warriors sent out by the unscrupulous Sith Lord Palpatine for 771 days now.
Lifeline
gittiest personITW
Level 12
Level 12
Posts: 4285
Joined: Tue May 28, 2019 4:27 pm

Re: How to keep programs open through a reboot?

Post by gittiest personITW »

Fair enough Karlchen.
Didn't think it would be easy even if it was possible.

The easiest way then, might be to do what JimAllyn said he didn't want to do.
Put all his programs that he is likely to be running in startup menu, then before rebooting, going into startup menu and choosing what would be started. That would only take a few seconds on those rare occassions a reboot is necessary.

Or
Custom Applications Menu applet, so everything is to hand and can be started up without searching too much for it. (yes, it does need to be set up though)

Keep well.
User avatar
karlchen
Level 23
Level 23
Posts: 18209
Joined: Sat Dec 31, 2011 7:21 am
Location: Germany

Re: How to keep programs open through a reboot?

Post by karlchen »

Hi, gittiest personITW.

Here is a very quick and very dirty approach from my side. (Very likely I will rewrite it using awk in order to get rid of the slow read commands.)
The following script, named get_running_user_processes.sh, collects the loaded user applications, i.e. the ones which will display icons in the window list in the bottom panel.

Code: Select all

#!/bin/bash

wmctrl -p -l | while read one two procID four five
do
  ps axu | grep -v "grep" | egrep "^${LOGNAME} {1,9}${procID}" | while read -r A B C D E F G H I J cmdSTR
  do
    echo "$cmdSTR" | sed -e 's#\\#/#g' -e 's#\t#/t#g'
  done
done
I know there are at least 2 deficiencies in it still:
  • one deficiency is the number of spaces between ${LOGNAME} and ${procID} should be variable. Need to lookup the appropriate regex notation.
  • commandlines of Wine commands might hold the Windows path separator backslash, which need to be converted to forward slash
  • commandlines of Wine commands might hold the character sequence "\t", which will be replaced by TAB. Current repair is a dirty workaround and unreliable
Anyway.
Assuming the known deficiencies will have been eliminated sooner or later, the list of commandlines would need to be written to a file.
This would have to happen, before the user logoff is initiated.

After the next login, the list of commands would be executed as a startup job.
For each commandline in the list, it would be nessary to check that it has not been launched already. In case it has not, then the commandline would be launched.
This part would be done by a second script, e.g. named restore_user_processes.sh
This script would be added to the Startup Applications and process the file holding the saved commandlines, provided the file is not empty.
After all commandlines have been processed the file would be truncated.

Once I have got that far, I am dead sure to learn about more deficiencies in my approach. Maybe even much earlier. :(
Because if the task were this trivial, then all DE's would have implemented it. :wink:

Karl
--
P.S.:
Sorry, jimallyn, for hijacking your thread for my childish scripting draft. I'll continue it in the appropriate sub-forum, if ever.
Last edited by karlchen on Wed Jun 16, 2021 3:36 pm, edited 1 time in total.
Reason: Fixed 2 deficiencies, implemented 1 new dirty trick, which will be unreliable
Image
The people of Alderaan have been bravely fighting back the clone warriors sent out by the unscrupulous Sith Lord Palpatine for 771 days now.
Lifeline
gittiest personITW
Level 12
Level 12
Posts: 4285
Joined: Tue May 28, 2019 4:27 pm

Re: How to keep programs open through a reboot?

Post by gittiest personITW »

Karlchen -
Call me impressed!
I'm still amazed at the versatility in the right hands.

OP should be pleasantly surprised.
User avatar
Flemur
Level 20
Level 20
Posts: 10096
Joined: Mon Aug 20, 2012 9:41 pm
Location: Potemkin Village

Re: How to keep programs open through a reboot?

Post by Flemur »

karlchen wrote: Wed Jun 16, 2021 7:54 amxfce has got an option in the logoff / reboot / shutdown dialogue box: Save session for future logins
That GUI/function is in package xfce4-session, but you have to be in an xfce session for it to work.
Please edit your original post title to include [SOLVED] if/when it is solved!
Your data and OS are backed up....right?
mikeflan
Level 17
Level 17
Posts: 7106
Joined: Sun Apr 26, 2020 9:28 am
Location: Houston, TX

Re: How to keep programs open through a reboot?

Post by mikeflan »

Parsing this might be an option:

Code: Select all

wmctrl -lx
User avatar
jimallyn
Level 19
Level 19
Posts: 9075
Joined: Thu Jun 05, 2014 7:34 pm
Location: Wenatchee, WA USA

Re: How to keep programs open through a reboot?

Post by jimallyn »

No need to apologize for "hijacking" my thread. I appreciate your efforts (and everybody's) to solve this, and even enjoy the "thinking out loud" on the way. It wouldn't have to be an automatic thing when shutting down, if I could run a script that makes the list of what's running then shut down as the last step of the script that would be great. I could put an icon for it on the desktop or the panel and all I would have to do is click it and it gets done. I thought I had seen a distro that had this feature before, and having run xfce a few times, that must be where I saw it. Having seen it before, I was kinda thinking, "well, it's got to be there somewhere." To me, it seems so useful that I'm surprised that not every desktop has that feature.

As usually happens when I ask a question, I am learning something. Thanks, gentlemen.
“If the government were coming for your TVs and cars, then you'd be upset. But, as it is, they're only coming for your sons.” - Daniel Berrigan
User avatar
jimallyn
Level 19
Level 19
Posts: 9075
Joined: Thu Jun 05, 2014 7:34 pm
Location: Wenatchee, WA USA

Re: How to keep programs open through a reboot?

Post by jimallyn »

mikeflan wrote: Wed Jun 16, 2021 9:41 pm Parsing this might be an option:
wmctrl -lx
Wow, that even tells me what document the program was working on, at least for some programs.
“If the government were coming for your TVs and cars, then you'd be upset. But, as it is, they're only coming for your sons.” - Daniel Berrigan
tellymandeus
Level 4
Level 4
Posts: 311
Joined: Tue Sep 10, 2013 2:31 am
Contact:

Re: How to keep programs open through a reboot?

Post by tellymandeus »

hey, jumped over from my thread on the same topic....

So, do I understand correctly that karichen's script is something I could manually run before I shut down, and then manually run when I start up again? that would be an acceptable workaround (I'll take anything that reduces the amount of effort this takes...)

reading the above comments tho, I'm not quite clear how I go about using this script, can anyone give me a short set of instructions (sorry for needing hand-holding) for how to use it?
Me: a non-techie Linux enthusiast running LM20.1 64-bit Cinnamon on a 2017 gamer pc I bought used...
Linux is like riding a bicycle: it's slightly more effort, but ultimately much more satisfying.
User avatar
karlchen
Level 23
Level 23
Posts: 18209
Joined: Sat Dec 31, 2011 7:21 am
Location: Germany

Re: How to keep programs open through a reboot?

Post by karlchen »

tellymandeus wrote: Sat Jun 19, 2021 5:13 pm So, do I understand correctly that karichen's script is something I could manually run before I shut down, and then manually run when I start up again?
Sorry to disppoint you. But what I had shared is a quick and dirty (stress on "very dirty") draft. Simply read my post above carefully.
And you will know that it is still many miles away from something, which can be used.

Though I am pretty sure I have stated so in a previous post, let me do so again:
If the task of implementing "Session saving" (before logoff) and "Saved Session restore" (after login) were as trivial as the few lines of bash code, which I had shared, then you could be dead sure that not only the xfce desktop would bring along this functionality, but also Cinnamon would.
Image
The people of Alderaan have been bravely fighting back the clone warriors sent out by the unscrupulous Sith Lord Palpatine for 771 days now.
Lifeline
gittiest personITW
Level 12
Level 12
Posts: 4285
Joined: Tue May 28, 2019 4:27 pm

Re: How to keep programs open through a reboot?

Post by gittiest personITW »

So the questions might be
How does xfce implement this feature?
and,
How would it be able to be adapted/implemented in cli rather than gui?


Also, looking in Software Manager, the description for Cinnamon-Session (I know I know) sounds like it is what you are after but maybe something is lost in translation.
The Cinnamon Session Manager is in charge of starting the core components of the Cinnamon desktop, and applications that should be launched at login time. It also features a way to save and restore currently running applications.

This package contains the binaries for the Cinnamon Session Manager, but no startup scripts. It is meant for those willing to start cinnamon-session by hand with the components of their choice, and for applications such as MDM that use cinnamon-session internally.

There is also the Mate Session Manager which has a more specific description:
This package contains a session that can be started from a display manager such as MDM. It will load all necessary applications for a full-featured user session.

The session manager also features the ability to save a running session and restore it later.

This version is configured to start the MATE desktop, based on the MATE panel.
tellymandeus
Level 4
Level 4
Posts: 311
Joined: Tue Sep 10, 2013 2:31 am
Contact:

Re: How to keep programs open through a reboot?

Post by tellymandeus »

@karlchen haha ok thanks sorry I think fatigue is eroding my reading comprehension

I'll look into cinnamon-session, it seems its part of cinnamon (not something I have to install) but it's not clear how to acces the functionality I'm looking for, will investigate....
Me: a non-techie Linux enthusiast running LM20.1 64-bit Cinnamon on a 2017 gamer pc I bought used...
Linux is like riding a bicycle: it's slightly more effort, but ultimately much more satisfying.
ocor
Level 1
Level 1
Posts: 37
Joined: Mon May 04, 2020 7:03 am

Re: How to keep programs open through a reboot?

Post by ocor »

Wow, thank you @karlchen! I have been looking for something similar, trying to cook up my own solution, with top as well as wmctrl. Your simple and 'dirty' script is far superior to what I have been able to come up with, though. I agree that it's not quite there yet, but it's a pretty good effort.

I am unable to suspend/resume or hibernate my system, so I am really happy with this.

Thanks!
Locked

Return to “Other topics”