How to detect that foreground process is waiting for input?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to detect that foreground process is waiting for input?
# 1  
Old 06-28-2013
How to detect that foreground process is waiting for input?

Hi,

I have to create a script (ksh or perl) that starts certain number of parallel jobs (another scripts), each of them runs as a foreground process in a separate session. Plus I start monitoring job that has to determine if any of those scripts is expecting input from operator, and switch to the corresponding session if necessary. My problem is that I have not found a good way to determine that process is expecting input. For the background process it's pretty easy: process state is "stopped" and this can be easily checked with 'ps' command. In case of foreground process this does not work. So far I tried to attach to the process with dbx or truss to see if it's hanging on 'read', but this approach seems too heavyweight. Could you suggest some better solution? Perl, shell, C, Java, etc. ... is ok as long as it's standard and does not require extra 3rd party or OS-specific stuff to install.
Thank you.
# 2  
Old 06-28-2013
Log each session to a flat file and check the end of the log file for a prompt?
# 3  
Old 06-28-2013
I do not control what happens in those sessions. Sorry I didn't mention that.
# 4  
Old 06-28-2013
If they can read from stdin without entering stopped (aka T) state, they're not actually background processes -- they are foreground ones, each in full control of their respective terminals. Proper background process will still be able to print but, when they try and read, will be suspended.

If you set -m in a script, you will be able to put a backgrounded process back into the foreground with the fg command, but how to do vice versa noninteractively, I'm not sure... C would be able to do it.

Last edited by Corona688; 06-28-2013 at 07:03 PM..
# 5  
Old 06-28-2013
Quote:
Originally Posted by Corona688
Proper background process will still be able to print
Not necessarily. To successfully write to the terminal from a background process, the process group must not be orphaned and either the terminal's tostop setting must be disabled or the process must ignore SIGTTOU.

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Can I convert a foreground process to NOHUP ?

OS : AIX 6.1/Solaris 10 After I started running a shell script, I've realized that it will take another 5 hours to complete. Is there anyway I could convert this foreground process to run in nohup mode so that I can go home peacefully ? I have the process ID $ ps -ef | grep... (4 Replies)
Discussion started by: kraljic
4 Replies

2. Shell Programming and Scripting

How can put a background process to the foreground

Hi, guys: I am working on my own shell using c. When I put a process into the background, how can I put it back to the foreground using tcsetpgrp? Thanks (3 Replies)
Discussion started by: tomlee
3 Replies

3. UNIX for Advanced & Expert Users

what is the diff b/w background and foreground process

What are all the difference between a Background and Foreground processes ?! A Background process does not have access to STDIN and OUT.. What else ? Is there any detailed description available somewhere ? (5 Replies)
Discussion started by: onequestion
5 Replies

4. UNIX for Advanced & Expert Users

Bringing a nohup process to foreground

Hi, I have used nohup command to run a process in background. i ran successfully and i exit from that terminal. But when i login for the next time I am not able to see the process but it is working, since I am getting a e-mail alert for error issue. Please let me know how to bring that process... (3 Replies)
Discussion started by: mbguy
3 Replies

5. UNIX for Dummies Questions & Answers

bringing a process to the foreground

If i have a single file i would just press fg but if i have multiple files running in the backgound and want to bring a specific one to the foreground how would i do that? Thanks!! (1 Reply)
Discussion started by: JamieMurry
1 Replies

6. Shell Programming and Scripting

Background and Foreground of a process within a script

I'm not sure if it is even possible but I figured if it was someone here would know how to do it... I am running a script which starts a bunch of processes in the background but there is one process I would like to bring back to the foreground when complete. Unfortunately the process that I... (2 Replies)
Discussion started by: ctruhn
2 Replies

7. UNIX for Advanced & Expert Users

make a foreground running process to run background without hang up

I've tried this a long time ago and was successful but could not remember how i did it. Tried ctrl+Z and then used bg % could not figure what i did after to keep it no hangup - not sure if used nohup -p pid, can u plz help me out if this can be done. Any help will be appreciated. (12 Replies)
Discussion started by: pharos467
12 Replies

8. Programming

Detecting if command is waiting for input

Hi, After doing a fork and executing a shell, we execute (third party) commands which are essentially non-interactive. But some of them ask for input, under some (unforeseeable) circumstances. When this happens we go on waiting for output. Their is timeout, of course, but we don't seem to know... (5 Replies)
Discussion started by: slash_blog
5 Replies

9. UNIX for Advanced & Expert Users

Process(s) ID waiting on IO?

Hello Experts!! My CPU is waiting a lot (around 33%) on I/O. I would like to find out what process(s) are waiting on the i/o. Below is my real time output of vmstat and sar. Thanks for you help !!!! Regards Citrus OS: AIX - 5L : /u2/oracle >oslevel 5.3.0.0 : /u2/oracle... (9 Replies)
Discussion started by: Citrus143
9 Replies

10. Linux

waiting process

how to know the information of the waiting process how to calculate the time of the process that it has taken to execute i want to make a program that Should be able to keep a log of the processes expired(The log should contain the starting time, expiry time, time slices used, total execution... (2 Replies)
Discussion started by: shukla_chanchal
2 Replies
Login or Register to Ask a Question