RLIMIT_STACK signal's


 
Thread Tools Search this Thread
Top Forums Programming RLIMIT_STACK signal's
# 1  
Old 04-10-2009
Java RLIMIT_STACK signal's

I'am expecting a signal, but no signal is received when the stack-size reaches 10 bytes.
Here in this code i'am setting rlim_cur=10bytes.
To be more precise, when it reaches 10 bytes the process must receive a SIGSEGV signal? But i find no signal being received.
Am i missing something in this code?
Thanks.
//stack.c

#include <sys/resource.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <signal.h>
#include <sys/mman.h>


int fact(int n)
{
// Recursive, for forcing a signal
if(n==0)return 1;
else
return n*fact(n-1);
}


static void sig_usr(int);


static void sig_usr( int signo)
{
if( signo == SIGSEGV){
printf("received signal, Stack size exceeded 10bytes!!\n");
exit(0);
}
}

int main (int argc, char *argv[])
{
struct rlimit limit;

if (signal(SIGSEGV, sig_usr)==SIG_ERR)
printf("can't catch signal");


//Set the stack size resource limit.
limit.rlim_cur =10;


if (setrlimit(RLIMIT_STACK, &limit) != 0) {
printf("setrlimit() failed with errno=%d\n", errno);
exit(1);
}

/* Get the Stack size resource limit. */
if (getrlimit(RLIMIT_STACK, &limit) != 0) {
printf("getrlimit() failed with errno=%d\n", errno);
exit(1);
}




printf("The soft limit is %lu\n", limit.rlim_cur);
printf("The hard limit is %lu\n", limit.rlim_max);

printf("\n%d\n",fact(10));
return 0;
}
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Case signal

Task 1: #!/bin/ksh if then echo "Usage : $0 Signalnumber PID" exit fi case "$1" in 1) echo "Sending SIGHUP signal" kill -SIGHUP $2 ;; 2) echo "Sending SIGINT signal" kill -SIGINT $2 ;; 3) echo "Sending SIGQUIT signal" kill -SIGQUIT $2 (3 Replies)
Discussion started by: Ramesh M
3 Replies

2. UNIX for Dummies Questions & Answers

signal() and sigsetjmp()

Hi, I am basically new to signals in UNIX. My question is, should the signal() command be called only once in the program? What will happen if it's called multiple times? I am trying to write an alarm program where the signal handler function changes in runtime. It just doesn't work if I... (2 Replies)
Discussion started by: bashdrew
2 Replies

3. Programming

Signal handling

I am trying to write a small program where I can send signals and then ask for an action to be triggered if that signal is received. For example, here is an example where I am trying to write a programme that will say you pressed ctrl*c when someone presses ctrl+c. My questions are what you would... (1 Reply)
Discussion started by: #moveon
1 Replies

4. Programming

Signal processing

We have written a deamon which have many threads. We are registering for the SIGTERM and trying to close main thread in this signal handling. Actually these are running on Mac OS X ( BSD unix). When we are unloading the deamon with command launchctl, it's sending SIGTERM signal to our process... (1 Reply)
Discussion started by: Akshay4u
1 Replies

5. Shell Programming and Scripting

Killed by signal 15.

Hi all I have Master script, Main script ,and 4 Child script. Master.sh #!/bin/bash /export/home/user/Main.shMain.sh #!/bin/bash /export/home/user/Child1.sh & /export/home/user/Child2.sh & /export/home/user/Child3.sh & /export/home/user/Child4.sh &I run only Master.sh script... (1 Reply)
Discussion started by: almanto
1 Replies

6. Programming

Signal catching

Hi! I want to catch all signals that my program receives print their name and then execute the default handler. Can you help me on that? I've tried the following code: #include <stdio.h> #include <unistd.h> #include <signal.h> void (*hnd)(int i); char signals = { "SIGHUP",... (7 Replies)
Discussion started by: dark_knight
7 Replies

7. Programming

problem with signal()

#include<signal.h> void suicide(); main() { printf("use CTRL \\ for exiting \n"); //signal(SIGINT,SIG_DFL); signal(SIGQUIT,suicide); for (;;); } void suicide() { printf("hello here you r in the suicide code "); } i was just starting with signals .. and tried this ,, but in the... (10 Replies)
Discussion started by: narendra.pant
10 Replies

8. Linux

Rlimit_stack

Hi, when i tried ulimit -a in my system i got "stack size (kbytes, -s) 10240" Am trying to reduce the stack size using setrlimit command using the following program... but am not getting the result... Can anybody help me in this...? #include <sys/resource.h>... (2 Replies)
Discussion started by: rvan
2 Replies

9. Programming

Signal Handling

Hi folks I'm trying to write a signal handler (in c on HPUX) that will catch the child process launched by execl when it's finished so that I can check a compliance file. The signal handler appears to catch the child process terminating however when the signal handler completes the parent... (3 Replies)
Discussion started by: themezzaman
3 Replies

10. Shell Programming and Scripting

Signal question

Who can explain the meaning of the &2 &1 or @, #, etc in the script? Is there any document which can explain the usage of these words in details? for example: ls /etc/sysconfig/network > /dev/null 2>&1 #@ bash, ksh and sh. Thanks in advance for ur advice. (1 Reply)
Discussion started by: GCTEII
1 Replies
Login or Register to Ask a Question