Operating System - HP-UX
1753502 Members
4818 Online
108794 Solutions
New Discussion юеВ

Moving a Foreground Process to the Background

 
SOLVED
Go to solution
Mark Blonde
Advisor

Moving a Foreground Process to the Background

Hello All,
In addition to running a process in the background using &, you can move a foreground process into the background. My script book says that in order to do so, you press the Ctrl+Z key and see the following (the ^Z is your Ctrl+Z key being echoed).
^Z[1] + Stopped (SIGTSTP)

PROBLEM: Pressing CTRL+Z Doesn't work for me!

I was wondering if it depends on the shell.

Lemme know!
If you don't have what you want, want what you have.
7 REPLIES 7
Helen French
Honored Contributor
Solution

Re: Moving a Foreground Process to the Background

Hi Mark:

Use these commands:

# fg [job] - bringing forground
# bg [job] - putting background

See man pages for more details. All these functions are shell specific.

HTH,
Shiju
Life is a promise, fulfill it!
Pete Randall
Outstanding Contributor

Re: Moving a Foreground Process to the Background

Mark,

I believe it depends on your stty settings (do a man on stty). I have yet to figure out what needs to be set - if I do, I'll let you know. And, yes, it is dependant on the shell.

Pete

Pete
MANOJ SRIVASTAVA
Honored Contributor

Re: Moving a Foreground Process to the Background

Hi Mark


do a stty | grep Z to know what is it set to . or may be try changing the shell .


Manoj Srivastava
steven Burgess_2
Honored Contributor

Re: Moving a Foreground Process to the Background

Hi

stty -a to see what your current settings are

To set to another parameter just

stty

To set a new value permanently add it to your .profile in your home directory

Here's what mine looks like

# Set up the terminal:
if [ "$TERM" = "" ]
then
eval ` tset -s -Q -m ':?hp' `
else
eval ` tset -s -Q `
fi
stty erase "^H" kill "^U" intr "^C" eof "^D"
stty hupcl ixon ixoff
tabs

Regards

Steve
take your time and think things through
Pete Randall
Outstanding Contributor

Re: Moving a Foreground Process to the Background

Mark,

On my system, stty shows:
stty
speed 9600 baud; evenp hupcl
intr = ^C; erase = ^H; kill = ^U;
eol2 = ^@; swtch = ^@;
susp = ^Z; dsusp = ^Y;
werase = ^@; lnext = ^V;
-inpck -istrip icrnl -ixany ixoff onlcr
-iexten echo echoe echok
-echoctl -echoke

This leads me to believe that we're after the suspend character. However, the following test:
$ xclock -digital -update 1
(I pressed ctrl-Z here)
[1] + Stopped xclock -digital -update 1
$
stops (or suspends) the clock. I would expect to be able to do a ctrl-Y to get it back but that doesn't work. I had to use Shiju's suggestion to bring it back to the foreground - where it resumed running.

Not much help, I'm afraid.

Pete

Pete
Stefan Schulz
Honored Contributor

Re: Moving a Foreground Process to the Background

Hi,

your shell has to be set up correctly to be able to suspend a running job. As the others mentioned check your stty settings. Of course you could set another Key than Ctrl-Z but this is not reconmendet. This can be done in your .profile.

After suspending a job you have to put it in background (bg) to keep it running. A suspended job is holded.

You can have several jobs running in background, which you can check with jobs.

To put one of these jobs in foreground just use fg %n where n is the number of the backgroundjob as shown with jobs.

Hope this helps

Regards Stefan
No Mouse found. System halted. Press Mousebutton to continue.
John Dvorchak
Honored Contributor

Re: Moving a Foreground Process to the Background

I am using the Korn shell (ksh) and I just did

> stty -a

to list the setup. I found that susp was undef. So I then typed

> stty susp ^Z

Now stty -a shows the susp defined as a control Z (^Z).

I then started a long find command.
I was then able to hit ctrl z and it suspended the job. With bg %1 I was able to put it in the background and with fg %1 brought it back.

You should look at your .profile and see if stty sets are made and if not you may want to add susp ^Z to set suspend.
If it has wheels or a skirt, you can't afford it.