Re: How to tbstat ??
Posted in 1994
On 8 Dec 1994 pss@kpdp.sps.mot.com wrote: > > Hello World, > > I would like to get the status of an online from within a C program. > > Instead of having to do a popen("tbstat -"). I wonder if anybody knows a > better way of doing it, something like get_online_status() or what ever > Informix has called it. There gotta be a function somewhere that does the > job. > > Looking forward to any good ideas > > Regards > > Per > > -- > > > Q/A Information & Systems I Kuwait Petroleum (Denmark) I Phone: +45 45984291 > Per St|vring S|rensen I Hummeltoftevej 49 I Private:+45 45768570 > pss@q8.dk I DK-2830 Virum I Fax: +45 42851418 > The following C code is used in another program which I had aquired. You should be able to modify it appropriately to get what you need. +----------------------------------------------------------------------------+ | | | | . . | | | ... ... | Darin Melin | | ..... ..... | Software Engineer, DBA | | .. ... .. | Business Systems Integration Group | | . . . | Semiconductor Products Sector | | | Mesa, AZ | | Motorola, Inc. | rp29560@email.sps.mot.com Phone:(602)-655-3627 | | | melin@hermes1.sps.mot.com | | | VP - Arizona Informix Users Group | +----------------------------------------------------------------------------+ | 'connectionLESS IS MORE' -- Data Broker | +----------------------------------------------------------------------------+ ******* cut here START OF C CODE ********************************************** /* * MODULE * tbstat_get.c * * FUNCTIONS * int partition_info(); * * DESCRIPTION * Executes the "tbstat -t" command and scans the output for the number of * pages allocated, number of pages used, number of data pages used, and * the number of extents for a given table. * * NOTES * The function partition_info() is intended to be called from Informix-4GL * programs, and therefore accept a single parameter (number of argument * values "passed" by the calling program) and return an integer value (number * of values returned to the calling program). * */ #include <stdio.h> #include <errno.h> int partition_num; int curr_partition; int num_extn; int num_page; int num_page_used; int num_page_data; int db_space_num; FILE *popen(); FILE *tbstat_out; char *fgets(); char buf[81]; /******************************************************************************* * NAME * partition_info * * DESCRIPTION * partition_info() executes the "tbstat -t" command in order to retrieve * information for the current table partition. The number of extensions, * number of pages allocated, number of pages used, and number of data * pages used and the db space are returned to the 4gl calling function. ******************************************************************************/ partition_info( nargs ) int nargs; { short cont_loop = 1; num_extn = (int)0; num_page = (int)0; num_page_used = (int)0; num_page_data = (int)0; if( nargs == 1 ) { poplong( &partition_num ); /* Get the partition number. */ if( ( tbstat_out = popen( "tbstat -t","r" ) ) == (FILE *)NULL ) printf( "Cannot execute tbstat command.\\n" ); else { while( fgets(buf,81,tbstat_out) != (char *)NULL && cont_loop ) { sscanf( buf,"%*s%*s%*s%*s%lx%*s%ld%ld%ld%*s%ld", &curr_partition, &num_page, &num_page_used, &num_page_data, &num_extn ); if( partition_num == curr_partition ) cont_loop = 0; } } pclose( tbstat_out ); } retint( num_page ); retint( num_page_used ); retint( num_page_data ); retint( num_extn ); db_space_num = (partition_num >> 24) & 0xff; retint( db_space_num ); return( 5 ); } /******** end of code *******************/