This discussion is archived
2 Replies Latest reply: Dec 12, 2011 2:40 AM by 904756 RSS

waitpid() function and Oracle 11R2 not work properly

675461 Newbie
Currently Being Moderated
Hi,
I have problem with our software compilation under RedHat. When I use ORACLE in my program, system function ‘waitpid’ work incorrect. I only login to ORACLE and logout. Program works correct when I remove code which login to ORACLE.
Function ‘waitpid’ check state child process. Normally when child finish waitpid return his pid. But when I build code with connect to ORACLE ‘waitpid’ return error :’No child processes.’ Problem is only after used login to ORACLE. Before connected to ORACLE is OK.

Algorytm:
‘waitpid‘ works ok.
Login to ORACLE
‘waitpid’ works incorrect.

I use:
1.     gcc v4.1.2 20080704 (Red Hat 4.1.2-48) x86_64-redhat-linux kernel 2.6.18-194.el5
2.     Red Hat Enterprise Linux Server release 5.5 (Tikanga)
3.     ORACLE 11.2.0.1.0

Could you help me? Where is problem?

When I tested this program under RedHat Enterprise Linux Server release 5.4 (Tikanga) kernel 2.6.18-164.el5, linker gcc v4.1.2 20080704 (Red Hat 4.1.2-46) and ORACLE 11.1.0.6.0 all works correct.


Under is example:

File ‘batch.sh’

#!/bin/bash

sleep 2
exit 0


File ‘test.c’

#include <time.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <sys/wait.h>

#include <sqlca.h>

const struct timespec const_timespec_sleep_time = {0, 250000000};

short fncRunScript(char *,char *, pid_t *);

void fncTestFork(char*lpszBatch);


int main(void)
{
printf("\nParent pid=%d\n\n",(int)getpid());

fncTestFork("batch.sh");


EXEC SQL BEGIN DECLARE SECTION;
char sql_user[200];
char sql_password[200];
EXEC SQL END DECLARE SECTION;

strcpy(sql_user,"user");
strcpy(sql_password,"pass");

EXEC SQL CONNECT :sql_user IDENTIFIED BY :sql_password;

if (sqlca.sqlcode<0) printf("\nSQL_CONNECT error\n\n");
else printf("\nSQL_CONNECT OK\n\n");

EXEC SQL COMMIT WORK RELEASE;



fncTestFork("batch.sh");


return 0;
}

/*----------------------------------------------------------------------------
fncRunScript
----------------------------------------------------------------------------*/
short fncRunScript(char sz_path,char  sz_param,pid_t *p_ret_pid)
{
int i_status;
char *sz_params[3];
pid_t pid, parent_pid;

sz_params[0] = sz_path;
sz_params[1] = sz_param;
sz_params[2] = NULL;

printf("Starting script:%s\n\n",sz_path);
parent_pid = getpid();

switch (pid = fork()) {
case -1 :
fprintf(stderr, "Could not start child process\n\n");
return(1);
case 0 :
printf("I am child process. My Pid=%d, my parent Pid=%d\n\n",(int)getpid(),(int)parent_pid);

if (execv(*sz_params, sz_params) == -1) {
printf("Could not launch program: %s\n, error: %s\n\n",sz_path,strerror(errno));
exit(1);
return(1);
} /* End if */

return(0);
default :
printf("Script has been launched. My Pid=%d, my child process Pid=%d\n\n",(int)getpid(),(int)pid);
} /* End switch */

return(0);

} /* fncRunScripts */


void fncTestFork(char* lpszBatch)
{
int i_status=0;
char sz_path[100];
pid_t ret_pid, pid;

strcpy(sz_path,lpszBatch);
fncRunScript(sz_path,NULL,&ret_pid);

while(1) {
pid = waitpid(-1,&i_status,WNOHANG);

if (pid > 0) {
printf("Process pid=%d, status=%d\n",(int)pid,i_status);

if(WIFEXITED(i_status))
{
printf("Child process exited.\nhas stopped with exit code=%d\n",WEXITSTATUS(i_status));
break;

} // (WIFEXITED(i_status))
} /* End if */
else if (pid==0) {
printf(">>> Process pid=%d, status=%d\n",(int)pid,i_status);
}
else {
perror("perror");
printf("Error. pid=%d\n",pid);
break;
}

nanosleep(&const_timespec_sleep_time, NULL);
} /* End while */
}

fIle ‘makefile’


MODULE_NAME = tst


ORALIB = $(ORACLE_HOME)/lib/

CXXOPTS = $(COMPCOMM) $(INCLUDEOPT) -I $(ORACLE_HOME)/precomp/public

PCCOPT= "define=__RHL__"

ORALIBS = -L$(ORALIB) -lclntsh `cat $(ORALIB)sysliblist` -lm -lpthread

ORAUSERID = "userid=indeksy/ind1cal"
INM = "iname="
ONM = "oname="
LNM = "lname="
CPPCFG = define=__RHL__ "config=/u01/app/indprd/pcinclude/cpp.cfg" $(ORAUSERID)
CCFG = "config=/u01/app/indprd/pcinclude/c.cfg" $(ORAUSERID)

CXX = g++
PCC = proc

COMPCOMM = $(CXXOPT) -ext -Wno-deprecated -D__RHL__

HOMEDIR = /u01/app/indprd/

LIBRARY_TARGET = $(HOMEDIR)lib/
LIBRARY_TARGET_H = $(HOMEDIR)include/

VERHDR = $(LIBRARY_TARGET_H)version.h

PRJDIR = $(HOMEDIR)$(MODULE_NAME)/

SRCDIR = $(PRJDIR)src/
HDRDIR = $(PRJDIR)include/
OBJDIR = $(PRJDIR)obj/
BINDIR = $(PRJDIR)bin/
PC = $(PRJDIR)proc/

TARGET = MODULE: $(MODULE_NAME)
INCLUDEOPT = -I $(LIBRARY_TARGET_H) -I $(HDRDIR)
LIBSEARCH = -L$(LIBRARY_TARGET) -lindc
MMTPSEARCH = -L$(LIBRARY_TARGET) -lpga

LIBH = $(LIBRARY_TARGET_H)indc.h
MMTPH = $(LIBRARY_TARGET_H)libpga.h

LIBRARY = $(LIBRARY_TARGET)libindc.a
MMTPLIB = $(LIBRARY_TARGET)libpga.a

ORALIB = $(ORACLE_HOME)/lib/
CXXOPTS = $(COMPCOMM) $(INCLUDEOPT) -I $(ORACLE_HOME)/precomp/public

ORALIBS = -L$(ORALIB) -lclntsh `cat $(ORALIB)sysliblist` -lm -lpthread

ORAUSERID = "userid=user/pass"
INM = "iname="
ONM = "oname="
LNM = "lname="
CPPCFG = "config=/u01/app/indprd/pcinclude/cpp.cfg" $(ORAUSERID)
CCFG = "config=/u01/app/indprd/pcinclude/c.cfg" $(ORAUSERID)


EXE_LIST = $(BINDIR)tst

all: $(EXE_LIST)
@echo Module $(MODULE_NAME): make finished.

OBJS = $(OBJDIR)tst.o

$(BINDIR)tst: $(OBJS) $(LIBRARY)
@echo Linking $@ $(CXXIINFO)
@$(CXX) $(CXXOPT) $(OBJS) $(LIBSEARCH) $(ORALIBS) -o $@
strip $(BINDIR)tst
@echo Finished $@ $(CXXINFO)

PROC_CMD = $(INM)test.c $(ONM)$(PC)test.c \
$(LNM)$(PC)test.l $(CPPCFG)

$(OBJDIR)tst.o: $(LIBH) $(INN_HDR) $(SRCDIR)test.c
@echo PROC precompilation "($(TARGET))" $@ $(CXXINFO)
@$(PCC) $(PCCOPT) $(PROC_CMD)
@echo Compiling "($(TARGET))" $(@F) $(CXXINFO)
@$(CXX) $(CXXOPTS) -c $(PC)test.c -o $@

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points