Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

signal.alarm function with resolution greater than 1 second?

I'm trying to build a python timeout exception that runs in milliseconds.

The python signal.alarm function has a 1 second resolution.

How would one get an equivalent function that requests a SIGALRM signal to a given process in, say milliseconds, as opposed to seconds?

I've found no simple solutions as of yet.

Thanks in advance for your input.

like image 767
Louis Avatar asked Sep 22 '10 15:09

Louis


People also ask

What does alarm() do in C?

The alarm() function is used to generate a SIGALRM signal after a specified amount of time elapsed.

What is SIGALRM signal?

SIGALRM is an asynchronous signal. The SIGALRM signal is raised when a time interval specified in a call to the alarm or alarmd function expires. Because SIGALRM is an asynchronous signal, the SAS/C library discovers the signal only when you call a function, when a function returns, or when you issue a call to sigchk .

How alarm works in Linux?

Since the kernel already keeps per-process data structures ( task_struct ), it just stores the desired alarm time in there. Then Linux just uses its internal timer system to register a callback at the specified time. Said callback then delivers the SIGALRM to your process.


1 Answers

Use signal.setitimer() instead.

like image 99
Aaron Digulla Avatar answered Oct 03 '22 00:10

Aaron Digulla