unix signals
4 posters
unix signals
Can u explain SIGCONT & SIGTSTP in a single program
Adipriya.B- Posts : 1
Points : 3
Join date : 2010-03-09
Age : 35
Re: unix signals
SIGCONT is a signal to continue a stopped process
SIGTSTP is a signal when a terminal stops...for example when you press CTRL+Z
SIGTSTP is a signal when a terminal stops...for example when you press CTRL+Z
Jay Dave- Posts : 4
Points : 4
Join date : 2010-03-03
Re: unix signals
Example Program
Output
- Code:
#include <signal.h>
#include <stdio.h>
void handler(int a)
{
printf("SIGTSTP handler : Main has been stopped and some operations done\n");
raise(SIGCONT);
}
void chandler(int a)
{
printf("SIGCONT handler : Some operations done before main method continues\n");
}
int main (void)
{
int i=0;
signal (SIGTSTP, handler);
signal(SIGCONT,chandler);
for(i=0;i<5;i++)
{
printf("Main thread is gng to be stopped\n");
raise(SIGTSTP);
}
}
Output
- Code:
Main thread is gng to be stopped
SIGTSTP handler : Main has been stopped and some operations done
SIGCONT handler : Some operations done before main method continues
Main thread is gng to be stopped
SIGTSTP handler : Main has been stopped and some operations done
SIGCONT handler : Some operations done before main method continues
Main thread is gng to be stopped
SIGTSTP handler : Main has been stopped and some operations done
SIGCONT handler : Some operations done before main method continues
Main thread is gng to be stopped
SIGTSTP handler : Main has been stopped and some operations done
SIGCONT handler : Some operations done before main method continues
Main thread is gng to be stopped
SIGTSTP handler : Main has been stopped and some operations done
SIGCONT handler : Some operations done before main method continues
Re: unix signals
SIGTSTP signal is used to stop a process and SIGCONT is used to continue a process and to do some special operations before a process continues.
In above example, handler() is used to handle SIGTSTP and chandler() is used to handle SIGCONT signal. Still im not very sure about signals concept. ll try to give even more better examples later.
In above example, handler() is used to handle SIGTSTP and chandler() is used to handle SIGCONT signal. Still im not very sure about signals concept. ll try to give even more better examples later.
Re: unix signals
thanks Christopher..It was a very good example
Jay Dave- Posts : 4
Points : 4
Join date : 2010-03-03
Re: unix signals
- Code:
#include<signal.h>
#include<stdlib.h>
main()
{
int pid;
if ((pid = fork()) < 0)
{
perror("fork");
exit(1);
}
if (pid == 0)
{
signal(SIGSTOP,SIG_DFL);
system("ps -l");
signal(SIGCONT,SIG_DFL);
system("ps -l");
for(;;);
}
else
{
printf("\n PARENT: sending SIGSTOP\n\n");
kill(pid,SIGSTOP);
sleep(3);
printf("\n PARENT: sending SIGCONT\n\n");
kill(pid,SIGCONT);
sleep(3);
}
}
[335818@oracleclient ~]$ gcc signal.c
[335818@oracleclient ~]$ ./a.out
- Code:
PARENT: sending SIGSTOP
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
4 S 652 636 633 0 75 0 - 16527 wait pts/3 00:00:00 bash
0 S 652 703 636 0 78 0 - 912 - pts/3 00:00:00 a.out
1 T 652 704 703 0 78 0 - 911 finish pts/3 00:00:00 a.out
0 R 652 705 704 0 79 0 - 15886 - pts/3 00:00:00 ps
PARENT: sending SIGCONT
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
4 S 652 636 633 0 75 0 - 16527 wait pts/3 00:00:00 bash
0 S 652 703 636 0 75 0 - 912 - pts/3 00:00:00 a.out
1 S 652 704 703 0 78 0 - 911 wait pts/3 00:00:00 a.out
0 R 652 706 704 0 79 0 - 15886 - pts/3 00:00:00 ps
Notice the 4rth process in the output.In this program, the child process is stopped and resumed.
In the first segment, you can notice that the child process has the status T denoting that it has been stopped.In the second segment,the same process has its status as S,showing that it has been resumed!
Last edited by Maithreyi on Mon Mar 15, 2010 3:53 pm; edited 1 time in total (Reason for editing : For better clarity)
Maithreyi- Posts : 76
Points : 142
Join date : 2010-03-03
Age : 36
Location : Haldia
Permissions in this forum:
You cannot reply to topics in this forum
|
|