Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c60abbe

Browse files
committed
code working status 1
0 parents commit c60abbe

31 files changed

+1100
-0
lines changed

‎ResourceLimits/resourceLimits.c‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <stdio.h>
2+
#include <signal.h>
3+
#include <fcntl.h>
4+
#include <sys/resource.h>
5+
#include <unistd.h>
6+
#include <string.h>
7+
8+
main(int argc ,char *argv[])
9+
{
10+
int fileDescriptor;
11+
int k;
12+
13+
char *buf = "Hello";
14+
15+
struct rlimit rLim = { 30 ,100};
16+
struct rlimit rlimGet;
17+
18+
setrlimit(RLIMIT_FSIZE ,&rLim); /*RLIMIT_FSIZE : setting maximum limit */
19+
20+
fileDescriptor = open(argv[1] ,O_CREAT | O_TRUNC | O_RDONLY ,0600);
21+
22+
getrlimit(RLIMIT_FSIZE ,&rlimGet);
23+
printf("Soft Link : %d\n" ,rlimGet.rlim_cur);
24+
printf("Hard Link : %d\n" ,rlimGet.rlim_max);
25+
26+
for(k = 0 ;k <20 ;k++)
27+
{
28+
printf("Attempting to write %d by 6-bytes\n" ,strlen(buf));
29+
write(fileDescriptor ,buf ,strlen(buf));
30+
printf("successfully written %d bytes \n" ,strlen(buf));
31+
}
32+
33+
close(fileDescriptor);
34+
}

‎SignalHandlers/signalBlocking.c‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include <stdio.h>
2+
#include <signal.h>
3+
4+
void signalHandler( int sigNum )
5+
{
6+
switch(sigNum)
7+
{
8+
case SIGTERM :
9+
printf("SIGTERM SIGNAL RECIEVED\N");
10+
break;
11+
case SIGINT :
12+
printf("SIGINT SIGNAL RECIEVED\N");
13+
break;
14+
case SIGCONT :
15+
printf("SIGCONT SIGNAL RECIEVED\N");
16+
break;
17+
}
18+
}
19+
20+
main()
21+
{
22+
char buffer[100] = "0円";
23+
24+
sigset_t block;
25+
26+
signal(SIGTERM ,signalHandler);
27+
signal(SIGINT ,signalHandler);
28+
signal(SIGCONT ,signalHandler);
29+
30+
sigemptyset(&block); /*refering to empty sigset_t variable so it doesnt refer to any signals*/
31+
sigaddset(&block ,SIGTERM); /*Adding signals to empty set*/
32+
sigaddset(&block ,SIGINT);
33+
34+
sigprocmask(SIG_BLOCK ,&block ,NULL); /*Blocking signal & providing list of Signals to be blocked as block*/
35+
36+
while(strcmp(buffer ,"n") != 0)
37+
{
38+
printf("Enter a string : ");
39+
gets(buffer);
40+
puts(buffer);
41+
}
42+
43+
sigprocmask(SIG_UNBLOCK ,&block ,NULL); /*UnBlocking signal*/
44+
45+
while(1)
46+
{
47+
printf("Program Running\n");
48+
}
49+
50+
return 0;
51+
52+
}

‎SignalHandlers/signal_AlarmPause.c‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <stdio.h>
2+
#include <signal.h>
3+
4+
void signalHandler( int sigNum )
5+
{
6+
printf("we are in signal handler module recieved signal %d %s\n" ,sigNum ,sys_siglist[sigNum]);
7+
}
8+
9+
main()
10+
{
11+
int ret;
12+
signal(SIGALRM ,signalHandler);
13+
14+
printf("About to call Alarm\n");
15+
16+
ret = alarm(10);
17+
18+
printf("alarm() system call returns %d\n" ,ret);
19+
20+
ret = alarm(20);
21+
22+
printf("alarm() system call returns %d\n" ,ret);
23+
printf("pause will block\n");
24+
25+
pause();
26+
27+
printf("SIGALARM is rasied and handled ,the flow continues\n");
28+
29+
30+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* inheriting signal handler by child process */
2+
#include <stdio.h>
3+
#include <signal.h>
4+
5+
void signalHandler( int sigNum )
6+
{
7+
int status;
8+
printf("In handler ,invoked in response to signum : %d\t%s signal\n " ,sigNum ,sys_siglist[sigNum]); /*sys_siglist : array of string which maps signal number to string names*/
9+
wait(&status);
10+
}
11+
12+
main()
13+
{
14+
pid_t pId;
15+
16+
signal(SIGCHLD ,signalHandler); /* SIGCHLD is normally sent to a process to notify that one of its child processes ended, so the parent process can collect its exit code.*/
17+
18+
pId = fork();
19+
if(pId == 0) /*Child Process*/
20+
{
21+
printf("Child process\n");
22+
exit(0);
23+
}
24+
else
25+
{
26+
printf("Parent process\n");
27+
getchar();
28+
}
29+
}

‎SignalHandlers/signal_kill.c‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* signal from one process to other : kil() */
2+
#include <stdio.h>
3+
#include <signal.h>
4+
5+
main()
6+
{
7+
pid_t pId;
8+
int status;
9+
10+
pId = fork();
11+
if( pId == 0 )
12+
{
13+
printf("child Process Activated : %d\n" ,getpid());
14+
}
15+
else
16+
{
17+
printf("Parent Process Activated : %d\n" ,getpid());
18+
kill(pId ,SIGKILL);
19+
wait(&status);
20+
printf("child Process is Killed\n");
21+
printf("Parent Terminated\n");
22+
23+
getchar();
24+
}
25+
26+
}

‎SignalHandlers/signal_raise.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* sending signal to itself : raise() */
2+
3+
#include <stdio.h>
4+
#include <signal.h>
5+
6+
main()
7+
{
8+
printf("we are in process with pId : %d\n" ,getpid());
9+
/*kill(getpid() ,SIGILL)*/
10+
11+
getchar();
12+
raise(SIGKILL);
13+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* Registering handler with the kernel */
2+
#include <stdio.h>
3+
#include <signal.h>
4+
5+
void sigHandler(int sigNo)
6+
{
7+
printf("In signal handler module recieved signal is %d %s\n" ,sigNo ,sys_siglist[sigNo]);
8+
}
9+
10+
main(void)
11+
{
12+
signal(SIGINT ,sigHanlder);
13+
14+
getchar();
15+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* Common method for multiple signal handling */
2+
#include <stdio.h>
3+
#include <signal.h>
4+
5+
/* execution of code can be aborted in signal handler itself by using the exit(0) beyond the */
6+
void handleSignal( int sigNo )
7+
{
8+
printf("In signal handler module recieved signal is %d %s\n" ,sigNo ,sys_siglist[sigNo]);
9+
}
10+
11+
main( void )
12+
{
13+
signal(SIGINT ,handleSignal); /* SIGINT : interrupt from keyboard CTRL+C */
14+
signal(SIGTERM ,handlerSignal); /* SIGTERM: termination signal *
15+
16+
getchar();
17+
}

‎SignalHandlers/signal_sigAction.c‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <stdio.h>
2+
#include <signal.h>
3+
4+
void sigHandler( int sigNum )
5+
{
6+
printf("we are in signal handler module recieved signal %d %s\n" ,sigNum ,sys_siglist[sigNum]);
7+
}
8+
9+
main()
10+
{
11+
struct sigaction action = { sigHandler };
12+
13+
sigaction(SIGINT ,&action ,NULL);
14+
15+
while(1)
16+
{
17+
};
18+
}

‎fileManagement/.gitkeep‎

Whitespace-only changes.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /