Operating System - HP-UX
1855866 Members
8374 Online
104107 Solutions
New Discussion

Re: background to foreground

 
SOLVED
Go to solution
Muthukumar_5
Honored Contributor

background to foreground

Hai.

I have two process running in a back ground. I am using /sbin/sh shell. I am getting the process status with ps command. How to invoke the process into foregroud.

I am getting ps with -aef option to know the status. How to get the job id of that process and use on fg command on /sbin/sh shell.

Thanks,
Muthukumar
Easy to suggest when don't know about the problem!
9 REPLIES 9
Navin Bhat_2
Trusted Contributor

Re: background to foreground

You could use the "jobs" command.
curt larson_1
Honored Contributor

Re: background to foreground

execute jobs to get the job numbers,
then fg jobNumber
SAHA
Honored Contributor

Re: background to foreground

Here is an example:

# netscape

(Ctrl-Z)

prompt returns

# jobs
[1] netscape

# fg 1

Thanks,
You must PASS failure on way to success !!!
Muthukumar_5
Honored Contributor

Re: background to foreground

Hai all.

Thanks for the reply.

jobs command not working for the requirement when the setup as,

node 1 <--> node 2

There is a sample script in node 2
----- test.ksh ----
#!/usr/bin/ksh
set -x
echo $hostname
sleep 10
echo $whoami
sleep 10
echo test over

#chmod +x test.ksh

remote execution from node 1 to node 2 happends as like
remsh node2 -l root -n "location/test.ksh 1>&- 2>&- &"

On node2,
I am seeing the process running with ps. But jobs are not displaying anything about that.

How to do the invokation of remotely started process in background to foregroud"?

Thanks,
Muthukumar.
Easy to suggest when don't know about the problem!
Rajesh D L
Frequent Advisor

Re: background to foreground

Hi,

Get the PID using ps -ef and bring the process into foreground using
fg PID

regards,
RDL.
Muthukumar_5
Honored Contributor

Re: background to foreground

Hai.

I collected the node2's process with ps as

#ps -ef | grep -v grep | grep test.ksh
root 545 543 0 18:35:21 ? 0:18 /usr/bin/ksh test.ksh
root 543 540 0 18:35:21 ? 0:00 sh -c test.ksh

# fg 545
sh: fg: The specified job does not exist.
# fg 543
sh: fg: The specified job does not exist.

# jobs
It is not showing anything.

What is the problem.

It was started at 18:35:21 but now 20:23:55.
Process started as same script after that in background had completed.

Thanks,
Muthukumar.
Easy to suggest when don't know about the problem!
curt larson_1
Honored Contributor

Re: background to foreground

the way your executing your remsh results in an immediate return without waiting for the remote command to complete. once that has occured your process on node2 becomes an independent process from the shell your running on node1. therefore, your remote process can not be brought to the foreground. you'll notice that the remote process now has init, ppid of 1, as it's parent process.
Muthukumar_5
Honored Contributor

Re: background to foreground

Hai.

You are correct.

Process status as
#ps -aef | grep -v grep | grep test.ksh
root 545 543 0 18:35:21 ? 0:22 /usr/bin/ksh test.ksh
root 543 540 0 18:35:21 ? 0:00 sh -c

#ps -aef | grep -v grep | grep 540
root 540 849 0 18:35:21 ? 0:02 remshd
root 543 540 0 18:35:21 ? 0:00 sh -c test.ksh

#ps -aef | grep -v grep | grep 849
root 849 1 0 May 20 ? 1:19 /usr/sbin/inetd
root 540 849 0 18:35:21 ? 0:02 remshd

So after the remote execution with 1>&- 2>&- &,the process will be executing alone.

During the stress test (around 100 process), some process 4-8 process are not progress it's execution.

How to check weather the background process are doing the execution or not?

Thanks,
Muthukumar
Easy to suggest when don't know about the problem!
curt larson_1
Honored Contributor
Solution

Re: background to foreground

the way you're executing the remsh, -n 1>&1 2>&-, the stdin is /dev/null and stdout along with stderr are closed. So, your not going to get any output from your process.

i suppose you could do a process tree and see if what command the process is executing, and hopefully be able to tell what the process is blocked on. glance could be helpful for doing this.

you also could rewrite your script to output some progress info to a log file.