Skip to content

Commit 8c93c73

Browse files
Add files via upload
1 parent 803d795 commit 8c93c73

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1864
-0
lines changed

Programs/10a.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import os
2+
rows, columns = os.popen('stty size', 'r').read().split()
3+
r=int(rows)
4+
c=int(columns)
5+
n = int(input("Enter number of rows:"))
6+
for i in range(int(r/2-n/2)):
7+
print()
8+
for i in range(n):
9+
for k in range(int(c/2)-int(n/2)):
10+
print(" ",end="")
11+
for k in range(n-i-1):
12+
print(" ",end="")
13+
for k in range(2*i+1):
14+
print("*",end="")
15+
print("\n",end="")
16+
for i in range(int(r/2-n/2)):
17+
print()
18+

Programs/10b.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
lower = int(input("Enter lower range: "))
2+
upper = int(input("Enter upper range: "))
3+
4+
for num in range(lower,upper + 1):
5+
if num > 1:
6+
for i in range(2,num):
7+
if (num % i) == 0:
8+
break
9+
else:
10+
print(num)

Programs/1b

16.4 KB
Binary file not shown.

Programs/1b.c

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include<stdio.h>
2+
#include<stdlib.h>
3+
#include<unistd.h>
4+
int main()
5+
{
6+
char *args[]={"./EXEC",NULL};
7+
execvp(args[0],args);
8+
printf("Ending\n");
9+
return 0;
10+
}
11+
12+
13+

Programs/1c.c

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*#include <stdio.h>
2+
#include <sys/types.h>
3+
#include <unistd.h>
4+
int main()
5+
{
6+
fork();
7+
printf("Hello world!\n");
8+
return 0;
9+
}
10+
*//*
11+
#include <stdio.h>
12+
#include <sys/types.h>
13+
#include <unistd.h>
14+
void forkexample()
15+
{
16+
17+
if (fork() == 0)
18+
printf("Hello from Child!\n");
19+
else
20+
printf("Hello from Parent!\n");
21+
}
22+
int main()
23+
{
24+
forkexample();
25+
return 0;
26+
}
27+
28+
*/
29+
#include <sys/types.h>
30+
#include <unistd.h>
31+
#include <stdio.h>
32+
int main()
33+
{
34+
int n =10;
35+
pid_t pid = vfork();
36+
if (pid == 0)
37+
{
38+
printf("Child process started\n");
39+
}
40+
else
41+
{
42+
printf("Now i am coming back to parent process\n");
43+
}
44+
printf("value of n: %d \n",n);
45+
return 0;
46+
}

Programs/1d.c

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include<stdlib.h>
2+
#include<stdio.h>
3+
#include<unistd.h>
4+
#include<sys/wait.h>
5+
void main()
6+
{
7+
pid_t id=fork();
8+
if(id==0)
9+
{
10+
printf("Child Process Started..ProcessID = %d\n", getpid());
11+
printf("In Child\n");
12+
for(int i=0;i<5;i++)
13+
{
14+
printf("In Child : %d\n",i);
15+
}
16+
printf("Child Finished\n");
17+
exit(0);
18+
}
19+
else
20+
{
21+
printf("Parent Process Started..ProcessID = %d\n", getpid());
22+
printf("In Parent\n");
23+
printf("Parent waiting\n");
24+
wait(NULL);
25+
printf("Parent Resumed\n");
26+
for(int i=0;i<5;i++)
27+
{
28+
printf("In parent : %d\n",i);
29+
}
30+
printf("Parent Finished\n");
31+
}
32+
}

Programs/1e.c

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include<stdio.h>
2+
#include<stdlib.h>
3+
int main()
4+
{
5+
char str[256], buf[256];
6+
printf("Enter command ");
7+
scanf("%s",str);
8+
sprintf(buf, "/bin/sh -c %s", str);
9+
system(buf);
10+
return 0;
11+
}

Programs/2a.c

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include<signal.h>
2+
#include<stdio.h>
3+
#include<unistd.h>
4+
#include<stdbool.h>
5+
#include<stdlib.h>
6+
bool flag=false;
7+
void alarmhandle(int sig)
8+
{
9+
printf("Input time expired\n");
10+
exit(1);
11+
}
12+
int main()
13+
{
14+
int a=0;
15+
printf("Input now in 10 seconds\n");
16+
sleep(1);
17+
alarm(10);
18+
signal(SIGALRM,alarmhandle);
19+
scanf("%d",&a);
20+
printf("You entered %d\n",a);
21+
}

Programs/2b.c

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include <signal.h>
2+
#include <stdio.h>
3+
#include <stdlib.h>
4+
#include <sys/types.h>
5+
#include <unistd.h>
6+
void sighup();
7+
void sigint();
8+
void sigquit();
9+
void main()
10+
{
11+
int pid;
12+
13+
if ((pid = fork()) < 0) {
14+
perror("fork");
15+
exit(1);
16+
}
17+
if (pid == 0) {
18+
signal(SIGHUP, sighup);
19+
signal(SIGINT, sigint);
20+
signal(SIGQUIT, sigquit);
21+
for (;;) ;
22+
}
23+
else
24+
{
25+
printf("\nPARENT: sending SIGHUP\n\n");
26+
kill(pid, SIGHUP);
27+
sleep(3);
28+
printf("\nPARENT: sending SIGINT\n\n");
29+
kill(pid, SIGINT);
30+
sleep(3);
31+
printf("\nPARENT: sending SIGQUIT\n\n");
32+
kill(pid, SIGQUIT);
33+
sleep(3);
34+
}
35+
}
36+
37+
38+
void sighup()
39+
{
40+
signal(SIGHUP, sighup);
41+
printf("CHILD: I have received a SIGHUP\n");
42+
}
43+
void sigint()
44+
{
45+
signal(SIGINT, sigint);
46+
printf("CHILD: I have received a SIGINT\n");
47+
}
48+
void sigquit()
49+
{
50+
printf("My DADDY has Killed me!!!\n");
51+
exit(0);
52+
}

Programs/2c.c

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include <stdio.h>
2+
#include <sys/types.h>
3+
#include <signal.h>
4+
#include <sys/ipc.h>
5+
#include <sys/shm.h>
6+
#include<stdlib.h>
7+
#include<unistd.h>
8+
void SIGINT_handler(int);
9+
void SIGQUIT_handler(int);
10+
int ShmID;
11+
pid_t *ShmPTR;
12+
void main(void)
13+
{
14+
int i;
15+
pid_t pid = getpid();
16+
key_t MyKey;
17+
if (signal(SIGINT, SIGINT_handler) == SIG_ERR) {
18+
printf("SIGINT install error\n");
19+
exit(1);
20+
}
21+
if (signal(SIGQUIT, SIGQUIT_handler) == SIG_ERR) {
22+
printf("SIGQUIT install error\n");
23+
exit(2);
24+
}
25+
MyKey = ftok(".", 's');
26+
ShmID = shmget(MyKey, sizeof(pid_t), IPC_CREAT | 0666);
27+
ShmPTR = (pid_t *) shmat(ShmID, NULL, 0);
28+
*ShmPTR = pid;
29+
for (i = 0; ; i++) {
30+
printf("From process %d: %d\n", pid, i);
31+
sleep(1);
32+
}
33+
}
34+
void SIGINT_handler(int sig)
35+
{
36+
signal(sig, SIG_IGN);
37+
printf("From SIGINT: just got a %d (SIGINT ^C) signal\n",
38+
sig); signal(sig, SIGINT_handler);
39+
}
40+
void SIGQUIT_handler(int sig)
41+
{
42+
signal(sig, SIG_IGN);
43+
printf("From SIGQUIT: just got a %d (SIGQUIT ^\\) signal"
44+
" and is about to quit\n",
45+
sig); shmdt(ShmPTR);
46+
shmctl(ShmID, IPC_RMID, NULL);
47+
exit(3);
48+
}
49+
50+

Programs/3a.c

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include<stdio.h>
2+
3+
#include<unistd.h>
4+
5+
#include<sys/types.h>
6+
7+
#include<sys/stat.h>
8+
9+
int main(int argc, char **argv)
10+
11+
{
12+
13+
struct stat fileStat;
14+
15+
stat("/home/sumit/Documents/UOS/abc.txt",&fileStat);
16+
17+
if(stat("/home/sumit/Documents/UOS/abc.txt",&fileStat) < 0)
18+
19+
{
20+
21+
printf("Failed\n");
22+
23+
return 1;
24+
25+
}
26+
27+
printf("---------------------------\n");
28+
29+
printf("File Size: \t\t%ld bytes\n",(long)fileStat.st_size);
30+
31+
printf("Number of Links: \t%ld\n",(long)fileStat.st_nlink);\
32+
printf("File inode: \t\t%ld\n",(long)fileStat.st_ino);
33+
34+
printf("File Permissions: \t");
35+
36+
37+
38+
printf( (S_ISDIR(fileStat.st_mode)) ? "d" : "-");
39+
40+
printf( (fileStat.st_mode & S_IRUSR) ? "r" : "-");
41+
42+
printf( (fileStat.st_mode & S_IWUSR) ? "w" : "-");
43+
44+
printf( (fileStat.st_mode & S_IXUSR) ? "x" : "-");
45+
46+
printf( (fileStat.st_mode & S_IRGRP) ? "r" : "-");
47+
48+
printf( (fileStat.st_mode & S_IWGRP) ? "w" : "-");
49+
50+
printf( (fileStat.st_mode & S_IXGRP) ? "x" : "-");
51+
52+
printf( (fileStat.st_mode & S_IROTH) ? "r" : "-");
53+
54+
printf( (fileStat.st_mode & S_IWOTH) ? "w" : "-"); printf( (fileStat.st_mode & S_IXOTH) ? "x" : "-"); printf("\n\n");
55+
56+
printf("The file %s a symbolic link\n", (S_ISLNK(fileStat.st_mode)) ? "is" : "is not"); return 0;
57+
58+
}

Programs/3b.c

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#include<stdio.h>
2+
#include<stdlib.h>
3+
#include <sys/stat.h>
4+
#include <sys/types.h>
5+
#include <unistd.h>
6+
int main()
7+
{
8+
char s[100];
9+
gets(s);
10+
//printf("%s",s);
11+
FILE *fp;
12+
if((fp=fopen(s,"r"))==NULL)
13+
return 1;
14+
int fn=0;
15+
fn=fileno(fp);
16+
struct stat sta;
17+
if(fstat(fn,&sta) < 0) return 1;
18+
printf("File size : %ld\n",(long)sta.st_size);
19+
printf("File INode Number : %ld\n",sta.st_ino);
20+
printf("File UID : %ld\n",(long)sta.st_uid);
21+
printf("File GID : %ld\nA",(long)sta.st_gid);
22+
printf("File Permissions: \t");
23+
printf( (S_ISDIR(sta.st_mode)) ? "d" : "-");
24+
printf( (sta.st_mode & S_IRUSR) ? "r" : "-");
25+
printf( (sta.st_mode & S_IWUSR) ? "w" : "-");
26+
printf( (sta.st_mode & S_IXUSR) ? "x" : "-");
27+
printf( (sta.st_mode & S_IRGRP) ? "r" : "-");
28+
printf( (sta.st_mode & S_IWGRP) ? "w" : "-");
29+
printf( (sta.st_mode & S_IXGRP) ? "x" : "-");
30+
printf( (sta.st_mode & S_IROTH) ? "r" : "-");
31+
printf( (sta.st_mode & S_IWOTH) ? "w" : "-");
32+
printf( (sta.st_mode & S_IXOTH) ? "x" : "-");
33+
printf("\n\n");
34+
printf("File type: ");
35+
switch (sta.st_mode & S_IFMT)
36+
{
37+
case S_IFBLK:
38+
printf("block device\n");
39+
break;
40+
case S_IFCHR:
41+
printf("character device\n");
42+
break;
43+
case S_IFDIR:
44+
printf("directory\n");
45+
break;
46+
case S_IFIFO:
47+
printf("FIFO/pipe\n");
48+
break;
49+
case S_IFLNK:
50+
printf("symlink\n");
51+
break;
52+
case S_IFREG:
53+
printf("regular file\n");
54+
break;
55+
case S_IFSOCK:
56+
printf("socket\n");
57+
break;
58+
default:
59+
printf("unknown?\n");
60+
break;
61+
}
62+
return 0;
63+
}

0 commit comments

Comments
 (0)