Highlighted
Absent Member.
Absent Member.
2158 views

[archive] How to tell if running in background

[Migrated content. Thread originally posted on 16 April 2004]

I have several programs that users run sequentially as a day end process. These same programs are run by some users as a scheduled background process using a keystroke file.

If there is an unexpected errror such as a file I-O error, our standard error handler displays the error to the user and prompts them to hit enter. If this happens during the background process it causes the keystrokes to be off and the process then doesn't complete properly.

Does anyone know of any way to tell if a program is running in the background?. I'm thinking if I knew that, when running in the background I could log the error a file and not prompt the user to press enter.

One note to consider, these are not executed using the -b option to the runtime due to a runtime error we ran into using that when a program does a DISPLAY WINDOW, it determining whether it's in the background can't depend on that.


Brad Hayes
0 Likes
10 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] How to tell if running in background

What operating system will you be executing on?
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] How to tell if running in background

We're operating on AIX, SCO Openserver and HP-UX.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] How to tell if running in background

That closes the Windows API suggestion 🙂
I believe I have heard about this before, have you tried this question for tech support?
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] How to tell if running in background

I talked to Tech support on friday, they didn't have a solution to directly tell if the process was running in tbe background or not.

We did talk about the STATION-ID in the Accept from System info. When running in the background it returns "(none)" as the station ID, which I did test under AIX and SCO Openserver, but it's undocumented so I'm a little concerned about whether I can really rely on it or not.

Based upon time frames I think it's going to have to be what I use though. I appreciate any thoughts though.

Brad
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] How to tell if running in background

hi phayes,
may I know how do you execute it in background?
Do toy apply the & at the end of the command?
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] How to tell if running in background

We're executing a shell script from the user's crontab that sets up the environment and then executes runcbl with the program name.

We also have the ability for the user to execute the same process online, in which case we call the same shell script from our applicatoin using the C$SYSTEM call.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] How to tell if running in background

A background process is a process without TTY.
This mean that if you can inquiry in some way the table of
process, you'll see that your process hasn't any tty assigned.
Since the wide variety of *nix you have to support, it can be much
difficult to solve this problem in a "elegant" way (e.g. calling some API function) instead of simply set up a environment variable in
the calling script, and then reading this variable from the program.

e.g.

suppose the script that sets up the environment for your program is SCRIPT.SH, then I'd create another script who's name is BACKGROUND.SH where I would set:

<<

BACKGROUND=yes; export BACKGROUND
. /path_to/SCRIPT.SH

<<

then the cron will call BACKGROUND.SH, while the program still call SCRIPT.SH

hope this help,
Luca
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] How to tell if running in background

I think I'm going to have to rely on the station-id value. Due to deployment issues redesiging our batch process by putting another script in front would be very difficult due to deployment issues. I appreciate the thoughts!

Brad
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] How to tell if running in background

..why don't you pass the "run mode" as a command line parameter ?

runcbl miprog.acu batch

then: accept run-mode from command-line
etc.

you can also use an environment variable in the script:

run_mode=batch
export run_mode
runcbl myprog.acu, then:
accept run-mode from environment "run_mode"
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] How to tell if running in background

I appreciate the input. Again good ideas but they would require changes to the environment external to the program which would be very undesirable for us as opposed to a cobol only change.

So far the station-id method seems to be working for me!
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.