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 7794301
In Process

The Archive Base Latest Questions

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

Today I observed a strange behavior I am hoping I can get some direction

  • 0

Today I observed a strange behavior I am hoping I can get some direction on.

Here’s what I’m doing…

With at least one process already running in background, I interrupt (Ctrl + Z) the foreground process and then place it in the background with bg.

Here are the results in zsh:

$ some-long-running-command
^Z
zsh: suspended  some-long-running-command
$ bg
[2]  - continued  some-long-running-command
$ jobs
[1]  + running    other-command-previously-run
[2]  - running    some-long-running-command
$

And here’s what it looks like in bash:

$ other-command-previously-run &
[1] 12345
$ some-long-running-command
^Z
[2]+  Stopped                 some-long-running-command
$ bg
[2]+ some-long-running-command &
$ jobs
[1]-  Running                 other-command-previously-run &
[2]+  Running                 some-long-running-command &
$ 

So why does bash keep the process placed in background with bg as the “current” process (indicated by “+” which will be resumed if fg is run), while zsh sets the “other” process as current? I can’t find any documentation suggesting the behavior would be different… Interestingly if you do several fg + ^Z + bg in zsh, the “current” process selection will “flip flop”.

Has anyone else seen this?

  • 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-01T22:44:20+00:00Added an answer on June 1, 2026 at 10:44 pm

    I can reproduce this behaviour in bash and zsh.

    My TL;DR answer: the behaviour you see in bash is documented. The behaviour you see in zsh is not (that I’ve found), and I have a theory, which might be wrong.


    Bash:

    The Bash Manual, section 7, "Job Control Basics" describes the behaviour of the builtin bg:

    The symbols ‘%%’ and ‘%+’ refer to the shell’s notion of the current job, which is the last job stopped while it was in the foreground or started in the background.

    Thus, from the point of view of bash, the current job is the last job either stopped in foreground or started in the background. This explains the behaviour noticed in the question:

    So why does bash keep the process placed in background with bg as the "current" process


    ZSH:
    I can’t explain this for zsh. The man zshmisc page, under section JOBS, explains what zsh means by the + and - in jobs:

    %% Current job.
    %+ Equivalent to ‘%%’.
    %- Previous job.

    It does not, however, explain what effect bg, fg and ^Z have on the processes in terms of relegating them to previous or current.

    My theory, which I’ve yet to verify by pestering the nice folks over in irc.freenode.net#zsh, is that zsh uses a "current-process stack"; bg pushes the current process to the end of the queue. This can be seen when playing with three processes thus:

    
    simont@charmander ~/repositories/SOTesting/bg
      $ one.sh&                                                                                 [1:52:41]
    [1] 98369
    
    simont@charmander ~/repositories/SOTesting/bg
      $ two.sh&                                                                                 [1:52:49]
    [2] 99293
    
    simont@charmander ~/repositories/SOTesting/bg
      $ three.sh                                                                                [1:52:51]
    ^Z
    [3]  + 973 suspended  three.sh
    
    simont@charmander ~/repositories/SOTesting/bg
      $ jobs                                                                                    [1:52:55]
    [1]    running    one.sh
    [2]  - running    two.sh
    [3]  + suspended  three.sh
    
    simont@charmander ~/repositories/SOTesting/bg
      $ bg                                                                                      [1:52:57]
    [3]  - 973 continued  three.sh
    
    simont@charmander ~/repositories/SOTesting/bg
      $ jobs                                                                                    [1:52:59]
    [1]    running    one.sh
    [2]  + running    two.sh
    [3]  - running    three.sh
    

    As we can see here, one and two are pushed down on the theoretical stack. three, being executed last(?) is the current process, denoted by the + from the jobs output.
    After three is suspended, it is still the current process, but after bg, it is pushed to the previous process and two, being the "top" process in the "stack" becomes the new current process.

    This, however, is conjecture; like I said, I haven’t got documented proof of this, and, honestly, the man zsh* pages are slightly complicated; I may have missed something.

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

Sidebar

Related Questions

Today we have received some strange exceptions on our production website. They all have
I observe some weird behavior today , the code is as follow : The
With great surprised I observed the following behavior today: Given a class class Foo
today I observed that the maven proprties defined in settings.xml overwrite the one in
Today, i observed an interesting behavior. I am using windows XP-sp3 OS. When i
Today, I have read that command's object in WPF can be serialized. And I'm
Today i have a little problem containing a File Upload. First some Infos: Rubyversion:
Today, while I was randomly reading the JavaScript patterns O'Reilly book, I found one
Today I made some tests and I am curious of the results. I made
I was wondering with my colleague today whether std::vector can be implemented to make

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.