Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how signal works

Status
Not open for further replies.

thaj

Programmer
May 13, 2002
12
0
0
AP
Hi,
I want to know how the signal works in the following code. The signal is called for every true and false condition and quits the application also. I want to know how signal works in the following code. Can anyone pls. help me to explain this.

while (1) {
/* check for a file to process */
/* process files until no more exist */
if ((wms_input = FindInbound(input_file_dir,input_file_ext)) != (char *)NULL) {
signal(SIGTERM, SIG_IGN);
sleep(1); /* used to ensure that file is completely ftped */

if((fp = fopen(wms_input,"r")) == NULL)
{
sprintf(jnlmsg, "Cannot open file %s",wms_input);
ssw_jnlreq(0,"AP",INF,pgm_nm,1000,jnlmsg,0,0);
signal(SIGTERM, term_handler);
sprintf(target_fname, "%s.err.old", wms_input);
rename(wms_input, target_fname);
continue;
}
sprintf(jnlmsg, "Processing file %s",wms_input);
ssw_jnlreq(0,"AP",INF,pgm_nm,1000,jnlmsg,0,0);

proc_ret = process_wmsinput();

if (proc_ret == 1) {
sprintf(jnlmsg, "Bad File Cont:%s.err.old",wms_input);
ssw_jnlreq(0,"AP",INF,pgm_nm,1000,jnlmsg,0,0);
signal(SIGTERM, term_handler);
sprintf(target_fname, "%s.err.old", wms_input);
rename(wms_input, target_fname);
continue;
}
else if (proc_ret == -1) {
sprintf(target_fname, "%s.unp.old", wms_input);
unlink(target_fname);
rename(wms_input, target_fname);
sprintf(jnlmsg, "Processing %s complete",wms_input);
ssw_jnlreq(0,"AP",INF,pgm_nm,1000,jnlmsg,0,0);
signal(SIGTERM, term_handler);
}
else {
sprintf(target_fname, "%s.old", wms_input);
unlink(target_fname);
rename(wms_input, target_fname);
sprintf(jnlmsg, "Processing %s complete",wms_input);
ssw_jnlreq(0,"AP",INF,pgm_nm,1000,jnlmsg,0,0);
signal(SIGTERM, term_handler);
}


}
else sleep(sleep_interval);
}
exit (0);
}

int term_handler(sig)
int sig;
{
ssw_jnlreq(0,"AP",INF,pgm_nm,1000,"Received shutdown notification",0,0);

exit(0);
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top