Operating System - OpenVMS
1827877 Members
1502 Online
109969 Solutions
New Discussion

Re: Looking for help:How to let a process write output to a file?

 
SOLVED
Go to solution
Z.K.
Frequent Advisor

Looking for help:How to let a process write output to a file?

Hi all,
I have a C program which executes some ".com" procedures periodically (using system(char *string)function).Now I start this program as a process (using sys$creprc).What should I do to let this process write it's "printf" messages and procedure execution messages into a disk file?
I tried to specify an output file in the sys$creprc function but got nothing but an empty file.
13 REPLIES 13
Uwe Zessin
Honored Contributor

Re: Looking for help:How to let a process write output to a file?

Did you check the process termination status in the accounting file?

A process has two output channels: 'SYS$OUTPUT' and 'SYS$ERROR'.
I suggest you assign the ERROR channel to the same file - maybe you find additional help in there.
.
Z.K.
Frequent Advisor

Re: Looking for help:How to let a process write output to a file?

Uwe,
thankyou for your quick reply.
I used the DCL command stop to stop the process.
----------------------------
Username: XTDL UIC: [DEFAULT]
Account: Finish time: 13-SEP-2006 14:45:54.56
Process ID: 20200C86 Start time: 13-SEP-2006 14:26:38.11
Owner ID: Elapsed time: 0 00:19:16.44
Terminal name: Processor time: 0 00:00:00.01
Remote node addr: Priority: 15
Remote node name: Privilege <31-00>: FFFFFFFF
Remote ID: Privilege <63-32>: FFFFFFFF
Remote full name:
Posix UID: -2 Posix GID: -2 (%XFFFFFFFE)
Queue entry: Final status code: 00002BD4
Queue name:
Job name:
Final status text: %SYSTEM-F-EXITFORCED, forced exit of image or process by SYS$
Page faults: 97 Direct IO: 7
Page fault reads: 9 Buffered IO: 20
Peak working set: 1824 Volumes mounted: 0
Peak page file: 164864 Images executed: 1
Martin Vorlaender
Honored Contributor

Re: Looking for help:How to let a process write output to a file?

Z.K.,

[sys$creprc]
>>>
I tried to specify an output file in the sys$creprc function but got nothing but an empty file.
<<<

You did pass the 'output' and 'error' parameters to sys$creprc as fixed-length descriptors pointing to the output files, or didn't you?

Please show us the call with enough context to give us some information to work with.

cu,
Martin
Z.K.
Frequent Advisor

Re: Looking for help:How to let a process write output to a file?

Hi Martin,
here is my codes.
$ type creprc.c
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#pragma member_alignment save
#pragma nomember_alignment
typedef struct
{
char quota;
int value;
}quota_entry_t;
#pragma member_alignment restore
struct dsc$descriptor_s descrBuild( char *name );
main()
{
unsigned int pid;
char image[64];
char input[64];
char output[64];
char error[64];
unsigned int prvnam[5];
quota_entry_t quota_array[]={{PQL$_BYTLM,128000},{PQL$_ASTLM,10},
{PQL$_WSQUOTA,4096},{PQL$_LISTEND}};
char quonam[4];
unsigned int quoval[4];
char prcnam[15];
unsigned int baspri;
unsigned int uic;
unsigned int stsflg;
int status;
// int prvadr[2];
long long prvadr;
struct dsc$descriptor_s img_descr;
struct dsc$descriptor_s inp_descr;
struct dsc$descriptor_s out_descr;
struct dsc$descriptor_s err_descr;
struct dsc$descriptor_s prc_descr;

strcpy(image,"$1$dga1:[oracle.schedule_bck]db_bck_sch.exe");
strcpy(input,"sys$input");
strcpy(output,"$1$dga1:[oracle.schedule_bck]db_bck_sch.out");
strcpy(error,"$1$dga1:[oracle.schedule_bck]db_bck_sch.out");
strcpy(prcnam,"DB_BCK_SCH");
prvadr=0xffffffffffffffff;
uic=0277; //uic use octal number
uic<<=16;
uic=uic|0200;
baspri=15;
stsflg=0x8;

img_descr=descrBuild(image);
inp_descr=descrBuild(input);
out_descr=descrBuild(output);
err_descr=descrBuild(error);
prc_descr=descrBuild(prcnam);

status=sys$creprc( &pid,
&img_descr,
&inp_descr,
&out_descr,
// 0,
&err_descr,
&prvadr,
quota_array,
// 0,
&prc_descr,
baspri,
uic,
0,
// stsflg);
0);
printf("sys$creprc execution status:%d\n",status);
}
struct dsc$descriptor_s descrBuild( char *name )
{
struct dsc$descriptor_s descr;

descr.dsc$w_length = strlen(name);
descr.dsc$b_dtype = DSC$K_DTYPE_T;
descr.dsc$b_class = DSC$K_CLASS_S;
descr.dsc$a_pointer = name;

return (descr);
}
Z.K.
Frequent Advisor

Re: Looking for help:How to let a process write output to a file?

Since the ".com" procedures my process executes does a lot of job,I wonder what quotas I have to set for this process.

Please take a look at this:
SYSGEN> SHOW PQL*
Parameter Name Current Default Min. Max. Unit Dynamic
-------------- ------- ------- ------- ------- ---- -------
PQL_DASTLM 24 24 -1 -1 Ast D
PQL_MASTLM 100 4 -1 -1 Ast D
PQL_DBIOLM 32 32 -1 -1 I/O D
PQL_MBIOLM 100 4 -1 -1 I/O D
PQL_DBYTLM 65536 65536 -1 -1 Bytes D
PQL_MBYTLM 1000000 1024 -1 -1 Bytes D
PQL_DCPULM 0 0 -1 -1 10Ms D
PQL_MCPULM 0 0 -1 -1 10Ms D
PQL_DDIOLM 32 32 -1 -1 I/O D
PQL_MDIOLM 100 4 -1 -1 I/O D
PQL_DFILLM 128 128 -1 -1 Files D
PQL_MFILLM 2048 2 -1 -1 Files D
PQL_DPGFLQUOTA 65536 65536 -1 -1 Pagelets D
internal value 4096 4096 0 -1 Pages D
PQL_MPGFLQUOTA 2000000 2048 -1 -1 Pagelets D
internal value 125000 128 128 -1 Pages D
PQL_DPRCLM 32 32 -1 -1 Processes D
PQL_MPRCLM 10 0 -1 -1 Processes D
PQL_DTQELM 16 16 -1 -1 Timers D
PQL_MTQELM 100 0 -1 -1 Timers D
PQL_DWSDEFAULT 5936 1024 -1 -1 Pagelets
internal value 371 64 0 -1 Pages
PQL_MWSDEFAULT 5936 512 -1 -1 Pagelets
internal value 371 32 32 -1 Pages
PQL_DWSQUOTA 11872 2048 -1 -1 Pagelets D
internal value 742 128 0 -1 Pages D
PQL_MWSQUOTA 11872 1024 -1 -1 Pagelets D
internal value 742 64 64 -1 Pages D
PQL_DWSEXTENT 786432 16384 -1 -1 Pagelets D
internal value 49152 1024 0 -1 Pages D
PQL_MWSEXTENT 786432 2048 -1 -1 Pagelets D
internal value 49152 128 128 -1 Pages D
PQL_DENQLM 128 128 -1 -1 Locks D
PQL_MENQLM 8192 30 -1 -1 Locks D
PQL_DJTQUOTA 4096 4096 -1 -1 Bytes D
PQL_MJTQUOTA 8192 0 -1 -1 Bytes D

Martin Vorlaender
Honored Contributor

Re: Looking for help:How to let a process write output to a file?

Z.K.,

hmmm...

the only nit I can find is that PQL$_LISTEND doesn't have an accompanying value, i.e. {PQL$_LISTEND} instead of {PQL$_LISTEND,0}.

Everything else looks right.

Do you have a return status of sys$creprc (i.e. when the program ends regularly, and not by STOP)?

cu,
Martin
Z.K.
Frequent Advisor

Re: Looking for help:How to let a process write output to a file?

Martin,
the C program Creprc.c I pasted before runs only once,it's job is to start another C program as a process which executes some ".com" procedures periodically.

>>the only nit I can find is that PQL$_LISTEND doesn't have an accompanying value, i.e. {PQL$_LISTEND} instead of {PQL$_LISTEND,0}.

I've tried this, they doesn't have any difference.

The return status of sys$creprc is "1",which means ss$_normal.

John Gillings
Honored Contributor

Re: Looking for help:How to let a process write output to a file?

Z.K.

I'm not sure I understand your problem, perhaps the issue is you want to be able to see the output in the file WHILE THE PROCESS IS RUNNING?

That's a bit tricky as, by default the SYS$OUTPUT channel for a process is not shared. However, it is possible to send the output of an arbitrary procedure or program to a shared file with the right DCL. The trick is to open a process permanent file with shared write access. Try this:

DET.COM
$ IF p1.NES."" THEN GOTO RUNIT
$ OPEN/WRITE/SHARE SHRLOG SYS$LOGIN:LOGFILE.LOG
$ @'F$ENVIRONMENT("PROCEDURE")/OUTPUT=SHRLOG RUNIT
$ CLOSE SHRLOG
$ EXIT
$ RUNIT: RUN cprogram
$ EXIT

Now, execute your detached process like this:

$ RUN/DETACHED/AUTHORIZE SYS$SYSTEM:LOGINOUT -
/INPUT=DET.COM/OUTPUT=DET.LOG

(or equivalent $CREPRC call)

Any output from your cprogram will be directed to the logfile SYS$LOGIN:LOGFILE.LOG. By default the EOF marker will NOT be updated, so you won't be able to see anything, BUT if you want to reset the EOF to the current end of file, you just need to request shared write access to the file, so:

$ OPEN/APPEND/SHARE LOG SYS$LOGIN:LOGFILE.LOG
$ CLOSE LOG

will make the contents of the file up to the time of the CLOSE visible. From then on normal access will show the contents of the log file. For example:

$ TYPE/TAIL SYS$LOGIN:LOGFILE.LOG

Repeat the OPEN & CLOSE sequence to update the EOF when required.
A crucible of informative mistakes
Ian Miller.
Honored Contributor

Re: Looking for help:How to let a process write output to a file?

because the C complier naturally aligns structures and the quota structure is not you need
pragma member_alignment save
#pragma nomember_alignment
typedef struct
{
char Quota;
int Value;
} QUOTA_ENTRY_T;
#pragma member_alignment restore

so of thing.

You may also find having a termination mailbox helpful as it is possible for the process to be created successfully and then exit immediately.

you are specifing SYS$INPUT as the name of the input file. Is this correct?
____________________
Purely Personal Opinion
Z.K.
Frequent Advisor

Re: Looking for help:How to let a process write output to a file?

Thanks John,
I did learn a lot from your reply.
My main objective is to start the process which will do some job (like backup,delete old backups,etc. using function int system(char *string))periodically,and write the execution logs into a disk file.But all I got was neither the job done nor the logs written in the disk file I specified.Someone told me the quotas caused the failure,but I don't know what quotas should I change to make it success.
Martin Vorlaender
Honored Contributor

Re: Looking for help:How to let a process write output to a file?

Z.K.,

you could try http://vms.pdv-systeme.de/users/martinv/quota_monitor.com to watch the process quotas, to find the one that eventually hits the ceiling.

HTH,
Martin
Joseph Huber_1
Honored Contributor
Solution

Re: Looking for help:How to let a process write output to a file?

Quickly scanning the code, I see a main reason why You see nothing:

the process created is running an image and HAS NO CLI (DCL).
So a "system(somecommand);" call simply fails. And if the process which does this is not checking the status and writes a message, nothing is written at all.

You have to create a process running the image
SYS$SYSTEM:LOGINOUT.EXE, and specify as input some DCL command-file which runs your image, and the logfile as sys$output and sys$error.
http://www.mpp.mpg.de/~huber
Z.K.
Frequent Advisor

Re: Looking for help:How to let a process write output to a file?

Ian,
>> because the C complier naturally aligns structures and the quota structure is not you need
pragma member_alignment save
#pragma nomember_alignment
...
#pragma member_alignment restore

I did specified these lines for the quota structure.

In the "OpenVMS System Services Reference Manual", I found the input parameter specifies an "Equivalence name to be associated with the logical name SYS$INPUT in the
logical name table of the created process".I used to set the "image" parameter for the image I want to start as a process,not sys$system:loginout.exe.

Seems Joseph resolved my question.
Thank John,Ian,Martin and Joseph!
Thank everyone!