Skip to main content

Folk and signals - C





I maked sample process in c it plays with folk function to make it pause and resume while clicking ctrl+c
If you have any questions please comment.

Code:

#include <stdio.h>
#include <unistd.h>
#include <signal.h>

void reverse_handler(int sig);
_Bool isPause=0;
_Bool isRunning=1;

int main()
{
int ppid;
int counter=0;
//make parent respond for ctrl+c (pause,resume).
signal(SIGINT,reverse_handler);
while(isRunning){
while(isPause==0)
{
/*code exec while process is resuming */
printf("\nc:%d",counter++);
fflush(stdout);
sleep(1);
}
//close parent after child is alive.
if((ppid=fork())==0){ exit(0); }
//make child respond for ctrl+c (pause,resume).
signal(SIGINT,reverse_handler);
//keep child alive and listening.
while(isPause==1){ /*code exec while process is pausing */ sleep(1); }
}
return 0;
}
//if process is pause made it resume and vice versa.
void reverse_handler(int sig){
if(isPause==0){
printf("\nPaused");
fflush(stdout);
isPause=1;
}
else if(isPause==1){
printf("\nresuming");
fflush(stdout);
isPause=0;
}
}

Thanks..

Popular posts from this blog

Server Project

V 0.1 1 - Ip 127.0.0.1 . 2 - Port 8090 . 3 - you can connect to server with netcat. 4 - Data format x,y like that (100,200) then player with move to that point. Source:  ServerProject_Src Scan:  Scan Link Exe :  ServerProject Scan :  Scan Link Keep Learning Keep Moving😎

Sorting Algorithms Visualization [TypeScript] ✌😜😜😜😜😜

Sorting Algorithms Visualization (SPFV)

eQuran V1

E-Quran link:  E-Quran i created a website for Quran Kareem with pure javascript and CSS and HTML without any library and that's the first version wait for me with the next project but don't forget to contact me for any question or suggestions  thank you......