#include <stdio.h>
     #include <sys/types.h>

#include <unistd.h>
#include <signal.h>
#include <pthread.h>
pid_t pid, childpid,parentpid;
int start=-1;
void *one,*two;
pthread_t th_a,th_b;
void * thread1(void *arg) {

int j,i;
	pid=getpid();
printf("thread1 %d",pid);
        sigset_t sigs;
        sigemptyset(&sigs);
        sigaddset(&sigs,SIGCONT);
        sigaddset(&sigs,SIGTSTP);
         pthread_sigmask(SIG_BLOCK,&sigs,NULL);
printf(".");
for(;;) {
	if(start>=0) {
		sleep(1);
		fflush(stdout);
		 while(start<0xFFFFF)
			start++;
		printf(".");
		kill(parentpid,SIGUSR1);
		exit(0);
		}
	sleep(1);
	};
}
void *thread2(void *arg) {
unsigned int j,i;
	pid=getpid();
printf("thread2 %d",pid);
start=0;
raise(SIGTSTP);
//pthread_kill(pthread_self() , SIGTSTP);
printf("start %d\n",start);
fflush(stdout);
	while(getchar()!='q') {
		printf("char\n");
		};
	}
void sighandler(int sig) {
	kill(childpid,SIGKILL);
	puts(" yes");	
	exit(0);
	}
void main(void) {
signal(SIGUSR1,sighandler);
childpid=fork();
if(childpid)   { /*parent*/
        sigset_t sigs;
        sigemptyset(&sigs);
        sigaddset(&sigs,SIGCONT);
        sigaddset(&sigs,SIGTSTP);
pthread_sigmask(SIG_BLOCK,&sigs,NULL);
        // sigprocmask(SIG_BLOCK,&sigs,NULL);
	printf("Checking if SIGSTOP and threads work together..");
	printf("childpid %d\n",childpid);
	fflush(stdout);
	sleep(10);
	kill(childpid,SIGKILL);
	printf(" no\n");
	exit(2);
}
else { /*child */
	usleep(1);
	sigset_t mask;
	pid=getpid();
	parentpid=getppid();
  printf("pid=%d, parentpid=%d\n",pid,parentpid);
	pthread_create(&th_a, NULL, thread1, one);
	thread2(two);
	}
}
