1838202 Members
5021 Online
110125 Solutions
New Discussion

ANother script horror

 
SOLVED
Go to solution
malay boy
Trusted Contributor

ANother script horror

static jmp_buf jump;

static void alarm_response(int sig)
{
(void) signal(sig,SIG_IGN);
longjmp(jump,sig);
return;
} /* alarm_response */



static void (*oldalrmsig)(int sig) = SIG_DFL;

oldalrmsig = signal(SIGALRM,SIG_IGN);

if (setjmp(mail_jump) == 0)
{
(void) signal(SIGALRM,alarm_response);
(void) alarm(120);
popen(...)
fgets();
pclose();
(void) alarm(0);
}
else
{
(void) fprintf(stderr,"Poopen timed out\n");
}
(void) signal(SIGALRM,oldalrmsig);

Hi Guru's
Above I taken out from Mr Clay reply from below :

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x173563f96280d711abdc0090277a778c,00.html

Could anybody shed some light on all those called function.What is it do ?.
OR how do I run above.Do I need to comply it or just insert it in the file and just run it.

p/s: Look like C programming.Ooooo!!! Now I know why I not passed my C,C++ exam during school days.

still learning,
mB


There are three person in my team-Me ,myself and I.
8 REPLIES 8
Rainer von Bongartz
Honored Contributor

Re: ANother script horror

Sure this is parts of a C-Program
using the system calls provided by HP-UX.

The mentioned functions are well defined in the manuals

e.g. man popen


Regards
Rainer
He's a real UNIX Man, sitting in his UNIX LAN making all his UNIX plans for nobody ...
malay boy
Trusted Contributor

Re: ANother script horror

Hi Rainer,
I didn't mean to give you 0 point.Miss click.If you reply again then I assign correct points.

regards
mB
There are three person in my team-Me ,myself and I.
Rainer von Bongartz
Honored Contributor

Re: ANother script horror

Sure this is parts of a C-Program
using the system calls provided by HP-UX.

The mentioned functions are well defined in the manuals

e.g. man popen


Regards
Rainer
He's a real UNIX Man, sitting in his UNIX LAN making all his UNIX plans for nobody ...
malay boy
Trusted Contributor

Re: ANother script horror

anybody ??? some light for the guy in the dark...

regards
mB
There are three person in my team-Me ,myself and I.
Dietmar Konermann
Honored Contributor
Solution

Re: ANother script horror

Well, it's a small example how to implement a watchdog for detecting a hanging popen() call in C language.

The setjump() function saves the current stack environment... then a signal handler (alarm_response) is set and a 120sec alarm is armed, before actually calling the popen().

If the popen times out (takes longer than 120sec) then the alarm pops, the kernel sends SIGALARM, which triggers the signal handler. This handler uses longjmp() to jump to the old stack environment, which is just the else branch of the if statement.

In the original thread a code fragment was posted as question... so Clay assumed that posting another fragment as answer would be OK (it is, IMHO).

See
man signal(2)
man alarm(2)
man popen(3S) pclose(3S)
man setjmp(3C)
man longjmp(3C)

Best regard...
Dietmar.
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)
Frank Slootweg
Honored Contributor

Re: ANother script horror

Why do you want to know?

This code comes from another thread and the question in that thread was not yours and was a very specific question.
malay boy
Trusted Contributor

Re: ANother script horror

Hi,
Well I want to pick up new skill.That the first/foremost reason why I join this forum.
Also I did not post the question in the first thread because generating the new thread give me a power to assign a point for those who help.


your humble servant,
mB.
There are three person in my team-Me ,myself and I.
David_246
Trusted Contributor

Re: ANother script horror

Hi Malay boy,

Just kick some ass :)

You're absolutely right, a forum is to learn things. This is something I always wanted to learn.

I do think, they gave you some good answers already. It's probably some part of C (C++), and "man
But he, I am not easily satisfied as well :
http://computer.howstuffworks.com/c.htm

Will tell you more. I think it's quiet a course you're asking for right now. But you awoke me, I am looking into the same course as well right now.
Never stop learning !!


Best Regs David
@yourservice