├── s ├── 1.txt ├── file ├── file.c └── file.cpp ├── sha ├── a.out ├── lab2.c └── lab1.c ├── shubham ├── a.out ├── Desktop │ ├── ab.c │ ├── hello1.c │ ├── hello.c │ ├── nano.save │ ├── prog1.c │ ├── fork.c │ ├── rohitk.c.save │ ├── ex.c │ ├── dir.c │ ├── seek.c │ ├── exam.c │ ├── open.c │ ├── zombie.c │ ├── thread2.c │ ├── seekcur.c │ ├── zombie1.c │ ├── sha.c │ ├── process.c │ ├── rohitk.c │ ├── thread3.c │ ├── lseek1.c │ ├── rohitthread.c │ ├── ca2.c │ ├── mychildparent.c │ ├── childparent.c │ ├── fork3.c │ ├── thread1.c │ ├── sai.c │ ├── fun.c │ ├── sai.c.save │ ├── semaphore.c │ ├── ct.c │ ├── mutex.c │ ├── thread.c │ └── prod.c ├── 3fork.c ├── zombie.c ├── orphan.c ├── test.txt ├── fork.c ├── pthread.c ├── childFactParentEven.c ├── processsync.c └── syncSema.c ├── pipe1.c ├── lpu ├── pipe1.c ├── pipe2.c ├── tt.c ├── pipe4.c ├── msg2.c ├── pipe.c ├── eval41.c ├── msg1.c ├── shm2.c ├── pr1.c ├── eval4.c ├── shm1.c ├── process.c ├── pipe3.c ├── t.c ├── dep.c ├── ipc.c ├── thread1.c ├── shared.c ├── ca2.c ├── shredmem.c ├── mutex.c ├── linked.c ├── index.c ├── caa.c └── semreadwite.c ├── pipe2.c ├── tt.c ├── pipe4.c ├── msg2.c ├── eval41.c ├── msg1.c ├── pipe.c ├── shm2.c ├── pr1.c ├── eval4.c ├── shm1.c ├── process.c ├── pipe3.c ├── t.c ├── ipc.c ├── dep.c ├── thread1.c ├── shared.c ├── ca2.c ├── .gitignore ├── shredmem.c ├── mutex.c ├── linked.c ├── index.c ├── caa.c └── semreadwite.c /s/1.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /s/file: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siraajul/Uni-OSLAB/HEAD/s/file -------------------------------------------------------------------------------- /sha/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siraajul/Uni-OSLAB/HEAD/sha/a.out -------------------------------------------------------------------------------- /s/file.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | printf("Hello"); 4 | } 5 | -------------------------------------------------------------------------------- /shubham/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siraajul/Uni-OSLAB/HEAD/shubham/a.out -------------------------------------------------------------------------------- /shubham/Desktop/ab.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/siraajul/Uni-OSLAB/HEAD/shubham/Desktop/ab.c -------------------------------------------------------------------------------- /s/file.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | std:cout<<"Hello World"; 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /shubham/Desktop/hello1.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | printf("hello world"); 5 | } 6 | -------------------------------------------------------------------------------- /shubham/Desktop/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main() 4 | { 5 | printf("Hello world"); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /shubham/Desktop/nano.save: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | void main() 4 | { 5 | char buff[50]; 6 | } 7 | -------------------------------------------------------------------------------- /shubham/Desktop/prog1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main() 4 | { 5 | printf("Hello world,this is my first program"); 6 | } 7 | -------------------------------------------------------------------------------- /pipe1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main() 5 | { 6 | int res; 7 | res=mkfifo("fifo",0777); 8 | printf("pipe created"); 9 | } 10 | 11 | -------------------------------------------------------------------------------- /lpu/pipe1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main() 5 | { 6 | int res; 7 | res=mkfifo("fifo",0777); 8 | printf("pipe created"); 9 | } 10 | 11 | -------------------------------------------------------------------------------- /shubham/Desktop/fork.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main() 5 | { 6 | pid_t P; 7 | fork(); 8 | fork(); 9 | fork(); 10 | printf("Hello\n"); 11 | } 12 | -------------------------------------------------------------------------------- /shubham/Desktop/rohitk.c.save: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | struct s1{ 5 | int a; 6 | int b; 7 | }; 8 | void *h (void *args) 9 | { 10 | struct s1 *arg=arg 11 | -------------------------------------------------------------------------------- /shubham/3fork.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | pid_t pid; 7 | fork(); 8 | fork(); 9 | fork(); 10 | printf("qwerty\n"); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /pipe2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | int main() 6 | { 7 | int res; 8 | res=open("fifo",O_WRONLY); 9 | write(res,"hello",5); 10 | printf("written",getpid()); 11 | } 12 | 13 | -------------------------------------------------------------------------------- /lpu/pipe2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | int main() 6 | { 7 | int res; 8 | res=open("fifo",O_WRONLY); 9 | write(res,"hello",5); 10 | printf("written",getpid()); 11 | } 12 | 13 | -------------------------------------------------------------------------------- /tt.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | FILE *wr; 5 | char buffer[20]; 6 | sprintf(buffer,"this is syntax"); 7 | wr=popen("wc -c","w"); 8 | fwrite(buffer,sizeof(char),strlen(buffer),wr); 9 | pclose(wr); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /lpu/tt.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | FILE *wr; 5 | char buffer[20]; 6 | sprintf(buffer,"this is syntax"); 7 | wr=popen("wc -c","w"); 8 | fwrite(buffer,sizeof(char),strlen(buffer),wr); 9 | pclose(wr); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /shubham/Desktop/ex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | int main() 6 | { 7 | printf("before exe\n"); 8 | execl("/bin/ps","ps",NULL); 9 | printf("after execl\n"); 10 | } 11 | -------------------------------------------------------------------------------- /shubham/Desktop/dir.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | DIR *dp; 6 | struct dirent *dptr; 7 | dp=opendir("dir1"); 8 | while(NULL!=(dptr=readdir(dp))) 9 | { 10 | printf("%d",dptr->d_type); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /shubham/Desktop/seek.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main() 5 | { 6 | int fd; 7 | char buff[50]; 8 | fd=open("f1",O_RDWR); 9 | lseek(fd,5,SEEK_END); 10 | int n=read(fd,buff,5); 11 | write(1,buff,n); 12 | } 13 | -------------------------------------------------------------------------------- /pipe4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main() 5 | { 6 | FILE *rd; 7 | char buff[100]; 8 | printf(buffer,"name first"); 9 | fd=popen("wc _c","w"); 10 | fwrite(buffer,sizeof(char),strlen(buffer),rd); 11 | pclose(rd); 12 | } 13 | -------------------------------------------------------------------------------- /lpu/pipe4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main() 5 | { 6 | FILE *rd; 7 | char buff[100]; 8 | printf(buffer,"name first"); 9 | fd=popen("wc _c","w"); 10 | fwrite(buffer,sizeof(char),strlen(buffer),rd); 11 | pclose(rd); 12 | } 13 | -------------------------------------------------------------------------------- /msg2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | key_t ke; 6 | ke=432; 7 | int size=20; 8 | char buff[100]; 9 | int msgid=msgget(ke,0666); 10 | 11 | 12 | int n=msgrcv(msgid,&buff,size,0,IPC_NOWAIT); 13 | printf("%s\n%d",buff,n); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /shubham/Desktop/exam.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main() 5 | { 6 | int n; 7 | char buff[50]; 8 | n=read(0,buff,50); 9 | fd=open("exam2",O_CREATE|O_RDWR,0777); 10 | write(fd,buff,50); 11 | } 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /lpu/msg2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | key_t ke; 6 | ke=432; 7 | int size=20; 8 | char buff[100]; 9 | int msgid=msgget(ke,0666); 10 | 11 | 12 | int n=msgrcv(msgid,&buff,size,0,IPC_NOWAIT); 13 | printf("%s\n%d",buff,n); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /eval41.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | int main() 7 | { 8 | FILE *rd; 9 | char buffer[50]; 10 | rd=popen("ls", "r"); 11 | fread(buffer, 1, 50, rd); 12 | 13 | printf("%s\n", buffer); 14 | pclose(rd); 15 | } 16 | -------------------------------------------------------------------------------- /lpu/pipe.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main() 5 | { 6 | char buffer[30]; 7 | FILE *wr; 8 | sprintf(buffer,"this is amessage"); 9 | wr=popen("wc -c","w"); 10 | fwrite(buffer,sizeof(char),strlen(buffer),wr); 11 | pclose(wr); 12 | } 13 | 14 | -------------------------------------------------------------------------------- /msg1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | key_t ke; 6 | ke=432; 7 | int size=20; 8 | char buff[100]; 9 | int msgid=msgget(ke,0666|IPC_CREAT); 10 | printf("enter the msg"); 11 | fgets(buff,size,stdin); 12 | msgsnd(msgid,&buff,size,0); 13 | } 14 | 15 | -------------------------------------------------------------------------------- /pipe.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main() 5 | { 6 | char buffer[30]; 7 | FILE *wr; 8 | sprintf(buffer,"this is amessage"); 9 | wr=popen("wc -c","w"); 10 | fwrite(buffer,sizeof(char),strlen(buffer),wr); 11 | pclose(wr); 12 | } 13 | 14 | -------------------------------------------------------------------------------- /lpu/eval41.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | int main() 7 | { 8 | FILE *rd; 9 | char buffer[50]; 10 | rd=popen("ls", "r"); 11 | fread(buffer, 1, 50, rd); 12 | 13 | printf("%s\n", buffer); 14 | pclose(rd); 15 | } 16 | -------------------------------------------------------------------------------- /lpu/msg1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | key_t ke; 6 | ke=432; 7 | int size=20; 8 | char buff[100]; 9 | int msgid=msgget(ke,0666|IPC_CREAT); 10 | printf("enter the msg"); 11 | fgets(buff,size,stdin); 12 | msgsnd(msgid,&buff,size,0); 13 | } 14 | 15 | -------------------------------------------------------------------------------- /shubham/Desktop/open.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | int main() 7 | { 8 | int n,fp; 9 | char a[100]; 10 | n=read(0,a,100); 11 | fp=open("file",O_CREAT|O_RDWR,0777); 12 | write(fp,a,100); 13 | } 14 | -------------------------------------------------------------------------------- /shm2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | key_t ke; 7 | ke=234; 8 | int size=100; 9 | int buff[100]; 10 | int shid=shmget(ke,size,0666); 11 | void *shmd= shmat(shid,NULL,0); 12 | printf("%X",(int)shmd); 13 | printf("message passed %s",(void*)shmd); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /lpu/shm2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | key_t ke; 7 | ke=234; 8 | int size=100; 9 | int buff[100]; 10 | int shid=shmget(ke,size,0666); 11 | void *shmd= shmat(shid,NULL,0); 12 | printf("%X",(int)shmd); 13 | printf("message passed %s",(void*)shmd); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /shubham/Desktop/zombie.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | int main() 6 | { 7 | pid_t p; 8 | p=fork(); 9 | if(p>0) 10 | { 11 | sleep(50); 12 | printf("parents"); 13 | } 14 | else 15 | { 16 | exit(0); 17 | printf("child process"); 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /lpu/pr1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | FILE *r1,*w1; 9 | char b[20]; 10 | r1=popen("ls","r"); 11 | fread(b,1,20,r1); 12 | w1=popen("wc -l","w"); 13 | fwrite(b,sizeof(char),strlen(b),w1); 14 | pclose(r1); 15 | pclose(w1); 16 | } 17 | -------------------------------------------------------------------------------- /pr1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | FILE *r1,*w1; 9 | char b[20]; 10 | r1=popen("ls","r"); 11 | fread(b,1,20,r1); 12 | w1=popen("wc -l","w"); 13 | fwrite(b,sizeof(char),strlen(b),w1); 14 | pclose(r1); 15 | pclose(w1); 16 | } 17 | -------------------------------------------------------------------------------- /shubham/Desktop/thread2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | void *th(int *m) 5 | { 6 | printf("hello %d",*m); 7 | } 8 | main() 9 | { 10 | pthread_t a; 11 | int m1=5; 12 | printf("h1"); 13 | pthread_create(&a,NULL,&th,&m1); 14 | pthread_join(a,NULL); 15 | printf("bye)"); 16 | } 17 | -------------------------------------------------------------------------------- /shubham/Desktop/seekcur.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | int fd; 6 | char buff[50]; 7 | fd=open("f30",O_RDONLY); 8 | int n=read(fd,buff,20); 9 | write(1,buff,n); 10 | lseek(fd,5,SEEK_CUR); 11 | int m=read(fd,buff,16); 12 | write(1,buff,m); 13 | lseek(fd,9,SEEK_CUR); 14 | 15 | } 16 | 17 | -------------------------------------------------------------------------------- /shubham/Desktop/zombie1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | int main() 7 | { 8 | pid_t p1; 9 | p1=fork(); 10 | if(p1>0) 11 | { 12 | sleep(10); 13 | for(int j=0;j<100;j++) 14 | { 15 | if(j%2!=0) 16 | { 17 | printf("%d",j); 18 | } 19 | } 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /shubham/Desktop/sha.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | int main() 5 | { 6 | int fd; 7 | fd=open("sha.txt",O_CREAT|O_RDWR,0666); 8 | int a; 9 | char buffer[100]; 10 | int bytes; 11 | a=write(fd,"hello world",50); 12 | int b; 13 | b=read(fd,buffer,10); 14 | printf("the value of b:%d",b); 15 | close(fd); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /eval4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main() 5 | { 6 | int res,n; 7 | char buffer[100]; 8 | res=open("fifo", O_RDONLY); 9 | n=read(res, buffer, 100); 10 | printf("total bytes read: %d \n", n); 11 | printf("%s was passed to me \n ", buffer); 12 | printf("process %d finished\n ", getpid()); 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /sha/lab2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define max 3 4 | int main() 5 | { 6 | pid_t pid; 7 | pid= fork(); 8 | if(pid==0) 9 | { 10 | printf("Child P2 id= %d \n",getpid()); 11 | printf("Child of P2 with Id= %d\n",getpid()); 12 | } 13 | 14 | else 15 | { 16 | printf("Parent Id= %d\n",getpid()); 17 | } 18 | 19 | } 20 | 21 | 22 | -------------------------------------------------------------------------------- /lpu/eval4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main() 5 | { 6 | int res,n; 7 | char buffer[100]; 8 | res=open("fifo", O_RDONLY); 9 | n=read(res, buffer, 100); 10 | printf("total bytes read: %d \n", n); 11 | printf("%s was passed to me \n ", buffer); 12 | printf("process %d finished\n ", getpid()); 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /shubham/zombie.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | pid_t pid; 7 | pid = fork(); 8 | if(pid>0) //parent 9 | { 10 | printf("This is from parent %d\n",pid); 11 | sleep(10); 12 | } 13 | else //child 14 | { 15 | printf("This is from child %d\n",pid); 16 | exit(0); 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /shubham/orphan.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | pid_t pid; 7 | pid = fork(); 8 | if(pid == 0) //child 9 | { 10 | printf("This is from child %d\n",pid); 11 | sleep(20); 12 | } 13 | else //parent 14 | { 15 | printf("This is from parent %d\n",pid); 16 | exit(0); 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /shubham/Desktop/process.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main() 5 | { 6 | pid_t p; 7 | p=fork(); 8 | if(p==0) 9 | { 10 | printf("childprocess %d ,pp%d",getpid(),getppid()); 11 | pid_t p1; 12 | p1=fork(); 13 | if(p1==0) 14 | { 15 | 16 | printf("cp %d",getpid()); 17 | printf("ppp%d",getppid()); 18 | } 19 | } 20 | } 21 | 22 | 23 | -------------------------------------------------------------------------------- /shm1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | key_t ke; 7 | ke=234; 8 | int size=100; 9 | int buff[100]; 10 | int shid=shmget(ke,size,0666|IPC_CREAT); 11 | void *shmd= shmat(shid,NULL,0); 12 | printf("%X",(int)shmd); 13 | printf("message to be sent"); 14 | read(0,buff,14); 15 | strcpy(shmd,buff); 16 | printf("you wrote %s",(void*)shmd); 17 | } 18 | 19 | -------------------------------------------------------------------------------- /lpu/shm1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | key_t ke; 7 | ke=234; 8 | int size=100; 9 | int buff[100]; 10 | int shid=shmget(ke,size,0666|IPC_CREAT); 11 | void *shmd= shmat(shid,NULL,0); 12 | printf("%X",(int)shmd); 13 | printf("message to be sent"); 14 | read(0,buff,14); 15 | strcpy(shmd,buff); 16 | printf("you wrote %s",(void*)shmd); 17 | } 18 | 19 | -------------------------------------------------------------------------------- /lpu/process.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main() 5 | 6 | { 7 | pid_t p; 8 | p=fork(); 9 | if(p==0) 10 | { 11 | excelp("\bin\ps" ,"ps", NULL) 12 | printf("child process is executing"); 13 | } 14 | else if (p>0) 15 | { 16 | wait(NULL); 17 | printf("parent is executing"); 18 | } 19 | else 20 | { 21 | printf("fork is failed"); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /process.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main() 5 | 6 | { 7 | pid_t p; 8 | p=fork(); 9 | if(p==0) 10 | { 11 | excelp("\bin\ps" ,"ps", NULL) 12 | printf("child process is executing"); 13 | } 14 | else if (p>0) 15 | { 16 | wait(NULL); 17 | printf("parent is executing"); 18 | } 19 | else 20 | { 21 | printf("fork is failed"); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /pipe3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | int main() 6 | { 7 | int fd[2],n; 8 | char buff[100]; 9 | pid_t P; 10 | pipe(fd); 11 | P=fork(); 12 | if(P>0) 13 | { 14 | close(fd[0]); 15 | printf("passing value to child"); 16 | write(fd[1],"hello",5); 17 | wait(); 18 | } 19 | else 20 | { 21 | close(fd[0]); 22 | n=read(fd[0],buffer,100); 23 | write(1,buff,n); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /lpu/pipe3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | int main() 6 | { 7 | int fd[2],n; 8 | char buff[100]; 9 | pid_t P; 10 | pipe(fd); 11 | P=fork(); 12 | if(P>0) 13 | { 14 | close(fd[0]); 15 | printf("passing value to child"); 16 | write(fd[1],"hello",5); 17 | wait(); 18 | } 19 | else 20 | { 21 | close(fd[0]); 22 | n=read(fd[0],buffer,100); 23 | write(1,buff,n); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /shubham/Desktop/rohitk.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | struct s1{ 5 | int a; 6 | int b; 7 | }; 8 | void *th (void *args) 9 | { 10 | struct s1 *arg=args; 11 | printf("hello %d",arg->a); 12 | } 13 | main() 14 | { 15 | pthread_t a; 16 | struct s1 arg; 17 | arg.a=10; 18 | arg.b=20; 19 | printf("hii"); 20 | pthread_create(&a,NULL,&th,&arg); 21 | pthread_join(a,NULL); 22 | printf("bye"); 23 | } 24 | -------------------------------------------------------------------------------- /shubham/Desktop/thread3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | struct s1{ 5 | int a; 6 | int b; 7 | }; 8 | void *th (void *args) 9 | { 10 | struct s1 *arg=args; 11 | printf("hello %d",arg->a); 12 | } 13 | main() 14 | { 15 | pthread_t a; 16 | struct s1 arg; 17 | arg.a=10; 18 | arg.b=20; 19 | printf("hii"); 20 | pthread_create(&a,NULL,&th,&arg); 21 | pthread_join(a,NULL); 22 | printf("bye"); 23 | } 24 | -------------------------------------------------------------------------------- /shubham/Desktop/lseek1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | int main() 7 | { 8 | int p,n,m; 9 | char b[100]; 10 | n=read(0,b,100); 11 | p=open("check",O_CREAT|O_RDWR,0777); 12 | write(1,"before seek",12); 13 | write(1,b,n); 14 | write(p,b,n); 15 | lseek(p,2,SEEK_SET); 16 | n=read(p,b,100); 17 | write(1,"after seek",13); 18 | write(1,b,m); 19 | } 20 | 21 | -------------------------------------------------------------------------------- /t.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | int fd[2]; 6 | char buff[15]; 7 | pip_t p; 8 | pipe(fd); 9 | p=fork(); 10 | if(p>0) 11 | { 12 | close(fd[0]); 13 | printf("this msg is from parent\n %d",getpid()); 14 | write(fd[1],"hello child",15); 15 | wait(); 16 | } 17 | else 18 | { 19 | close(fd[1]); 20 | int a=read(fd[0],buff,15); 21 | printf("the msg is read by child\n"); 22 | write(1,buff,a); 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /lpu/t.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | int fd[2]; 6 | char buff[15]; 7 | pip_t p; 8 | pipe(fd); 9 | p=fork(); 10 | if(p>0) 11 | { 12 | close(fd[0]); 13 | printf("this msg is from parent\n %d",getpid()); 14 | write(fd[1],"hello child",15); 15 | wait(); 16 | } 17 | else 18 | { 19 | close(fd[1]); 20 | int a=read(fd[0],buff,15); 21 | printf("the msg is read by child\n"); 22 | write(1,buff,a); 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /shubham/test.txt: -------------------------------------------------------------------------------- 1 | //atleast2 thread call procducer and 2 thread call consumer func 2 | buffer n 3 | when producer produces N+1 => 1 4 | no other producer should produce 5 | no consumer can consume 6 | 7 | consumer will consume N-1 8 | no other consumer can consume 9 | no producer can produce 10 | //progress 11 | //condtion variable 12 | pthread_cond_t x,y; 13 | 14 | pthread_cond_wait(&x); //consumer 15 | pthread_cond_signal(&prod); //producer 16 | -------------------------------------------------------------------------------- /shubham/Desktop/rohitthread.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | void *func1(); 5 | struct s1{ 6 | int a; 7 | int b; 8 | }; 9 | void *func1 (void *args) 10 | { 11 | struct s1 *arg=args; 12 | int res; 13 | res=(arg->a) * (arg->b); 14 | printf("%d",res); 15 | } 16 | int main() 17 | { 18 | pthread_t th; 19 | struct s1 arg; 20 | arg.a=10; 21 | arg.b=20; 22 | pthread_create(&th,NULL,&func1,&arg); 23 | pthread_join(th,NULL); 24 | } 25 | -------------------------------------------------------------------------------- /shubham/Desktop/ca2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main() 5 | { 6 | pid_t p; 7 | p=fork(); 8 | switch(p) 9 | { 10 | case 1: 11 | printf("\n error"); 12 | break; 13 | case 0: 14 | printf("\n child c1 is executing %d",getppid()); 15 | fork(); 16 | printf("\n child c11 is executing %d",getppid()); 17 | printf("\n child c12 is executing %d",getppid()); 18 | break; 19 | default: 20 | printf("\n parents executing %d",p); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ipc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | 5 | { 6 | int c; 7 | char buffer[50]; 8 | int fd[2]; 9 | char a; 10 | pid_t p; 11 | pipe(fd); 12 | p=fork(); 13 | if(p>0){ 14 | close(fd[0]); 15 | printf("parent sending amsg\n"); 16 | write(fd[1],"2",1); 17 | wait(); 18 | } 19 | else 20 | { 21 | close(fd[1]); 22 | printf("\n child is reading"); 23 | int n=read(fd[0],buffer,1); 24 | c =atoi(buffer); 25 | printf("\n%d",2*c); 26 | printf("\n%d",3*c); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /dep.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | int fd[2]; 6 | int a; 7 | pid_t p; 8 | pipe(fd); 9 | p=fork(); 10 | if(p>0){ 11 | close(fd[0]); 12 | printf("parent sending amsg\n"); 13 | write(fd[1],"2",1); 14 | wait(); 15 | } 16 | else 17 | { 18 | close(fd[1]); 19 | printf("\n child is reading"); 20 | int n=read(fd[0],a,1); 21 | char b; 22 | int c; 23 | printf("%c",a); 24 | c=(2*(int)a); 25 | printf("%d",c); 26 | b=(char)c; 27 | write(1,b,n); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lpu/dep.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | int fd[2]; 6 | int a; 7 | pid_t p; 8 | pipe(fd); 9 | p=fork(); 10 | if(p>0){ 11 | close(fd[0]); 12 | printf("parent sending amsg\n"); 13 | write(fd[1],"2",1); 14 | wait(); 15 | } 16 | else 17 | { 18 | close(fd[1]); 19 | printf("\n child is reading"); 20 | int n=read(fd[0],a,1); 21 | char b; 22 | int c; 23 | printf("%c",a); 24 | c=(2*(int)a); 25 | printf("%d",c); 26 | b=(char)c; 27 | write(1,b,n); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lpu/ipc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | 5 | { 6 | int c; 7 | char buffer[50]; 8 | int fd[2]; 9 | char a; 10 | pid_t p; 11 | pipe(fd); 12 | p=fork(); 13 | if(p>0){ 14 | close(fd[0]); 15 | printf("parent sending amsg\n"); 16 | write(fd[1],"2",1); 17 | wait(); 18 | } 19 | else 20 | { 21 | close(fd[1]); 22 | printf("\n child is reading"); 23 | int n=read(fd[0],buffer,1); 24 | c =atoi(buffer); 25 | printf("\n%d",2*c); 26 | printf("\n%d",3*c); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /shubham/fork.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | pid_t pid; 6 | printf("1.This is the parents id %d\n",getpid()); //getpid() fetches the PID of the current running process 7 | pid = fork(); //creates a new process (child process) 8 | //wait(); 9 | printf("2.This is the PID %d and parent PPID %d\n",pid,getppid()); //getppid will return the parent PID 10 | printf("3.This is the PID %d and parent PPID %d\n",pid,getppid()); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /shubham/pthread.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void* funFirst() 5 | { 6 | printf("First Thread Function\n"); 7 | } 8 | 9 | void* funSecond(void *msg) 10 | { 11 | printf("%s",(char*)msg); 12 | } 13 | int main() 14 | { 15 | pthread_t t1,t2,t3; 16 | char *msg = "Hi\n"; 17 | int a = pthread_create(&t1,NULL,funFirst,NULL); 18 | int b = pthread_create(&t2,NULL,funSecond,msg); 19 | pthread_join(t1,NULL); 20 | pthread_join(t2,NULL); 21 | return 0; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /shubham/childFactParentEven.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | pid_t pid; 6 | printf("1.This is the parents id %d\n",getpid()); //getpid() fetches the PID of the current running process 7 | pid = fork(); //creates a new process (child process) 8 | //wait(); 9 | printf("2.This is the PID %d and parent PPID %d\n",pid,getppid()); //getppid will return the parent PID 10 | printf("3.This is the PID %d and parent PPID %d\n",pid,getppid()); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /shubham/Desktop/mychildparent.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main() 5 | { 6 | pid_t P; 7 | P=fork(); 8 | switch(P) 9 | { 10 | case1: 11 | printf("error"); 12 | break; 13 | case0: 14 | printf("child executing"); 15 | printf("iam child my id is:%d\n",getpid()); 16 | printf("my parents id is:%d\n",getppid()); 17 | break; 18 | default: 19 | printf("parentrs executing"); 20 | printf("iam parent having id:%d\n",getpid()); 21 | printf("my child id is:%d\n",P); 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /shubham/Desktop/childparent.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main() 5 | { 6 | pid_t P; 7 | P=fork(); 8 | printf("%d",P); 9 | switch(P) 10 | { 11 | case1: 12 | printf("error"); 13 | break; 14 | case0: 15 | printf("child executing"); 16 | printf("iam child my id is:%d\n",getpid()); 17 | printf("my parents id is:%d\n",getppid()); 18 | break; 19 | default: 20 | printf("parentrs executing"); 21 | printf("iam parent having id:%d\n",getpid()); 22 | printf("my child id is:%d\n",P); 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /shubham/Desktop/fork3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | main() { 4 | int i; 5 | 6 | // create 3 child processes 7 | for (i = 0; i < 3; i++) { 8 | if (fork() == 0) { 9 | printf("Child process no.%d with ID: %d created from parent process\n", i); 10 | break; 11 | } 12 | } 13 | // wait for each child process to finish 14 | 15 | } 16 | -------------------------------------------------------------------------------- /thread1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | void *func(); 5 | struct s 6 | { 7 | int x,y; 8 | }; 9 | void *func1(void *args) 10 | { 11 | struct s *arg=args; 12 | int result; 13 | result=(arg->x) + (arg->y); 14 | printf("%d",result); 15 | } 16 | int main() 17 | { 18 | pthread_t th; 19 | struct s arg; 20 | printf("enter first number: "); 21 | scanf("%d",&arg.x); 22 | printf("enter second number:"); 23 | scanf("%d",&arg.y); 24 | pthread_create(&th,NULL,&func1,&arg); 25 | 26 | pthread_join(th,NULL); 27 | } 28 | 29 | -------------------------------------------------------------------------------- /lpu/thread1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | void *func(); 5 | struct s 6 | { 7 | int x,y; 8 | }; 9 | void *func1(void *args) 10 | { 11 | struct s *arg=args; 12 | int result; 13 | result=(arg->x) + (arg->y); 14 | printf("%d",result); 15 | } 16 | int main() 17 | { 18 | pthread_t th; 19 | struct s arg; 20 | printf("enter first number: "); 21 | scanf("%d",&arg.x); 22 | printf("enter second number:"); 23 | scanf("%d",&arg.y); 24 | pthread_create(&th,NULL,&func1,&arg); 25 | 26 | pthread_join(th,NULL); 27 | } 28 | 29 | -------------------------------------------------------------------------------- /shubham/Desktop/thread1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | void *fun1(); 4 | void *fun2(); 5 | int main() 6 | { 7 | pthread_t th,th1; 8 | int i,j; 9 | pthread_create(&th,NULL,&fun1,NULL); 10 | pthread_create(&th1,NULL,&fun2,NULL); 11 | pthread_join(th,NULL); 12 | pthread_join(th1,NULL); 13 | printf("back to main"); 14 | } 15 | void *fun1() 16 | { 17 | for (int i=1;i<100;i++) 18 | { 19 | if(i%2==0) 20 | printf(i); 21 | } 22 | } 23 | void *fun2() 24 | { 25 | for (int j=1;j<100;j++) 26 | { 27 | if (j%2!=0) 28 | printf(j); 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /lpu/shared.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | int main() 7 | { 8 | int i; 9 | void *shared_memory; 10 | char buff[100]; 11 | int shmid; 12 | shmid=shmget((key_t)2345,1000,0666|IPC_CREAT); 13 | printf("key of shared memory is %d\n",shmid); 14 | shared_memory=shmat(shmid,NULL,0); 15 | printf("process attached at %X\n",(int)shared_memory); 16 | printf("Enter some data to write to shared memory\n"); 17 | read(0,buff,100); 18 | strcpy(shared_memory,buff); 19 | printf("you wrote:%s\n",shared_memory); 20 | } 21 | 22 | -------------------------------------------------------------------------------- /shared.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | int main() 7 | { 8 | int i; 9 | void *shared_memory; 10 | char buff[100]; 11 | int shmid; 12 | shmid=shmget((key_t)2345,1000,0666|IPC_CREAT); 13 | printf("key of shared memory is %d\n",shmid); 14 | shared_memory=shmat(shmid,NULL,0); 15 | printf("process attached at %X\n",(int)shared_memory); 16 | printf("Enter some data to write to shared memory\n"); 17 | read(0,buff,100); 18 | strcpy(shared_memory,buff); 19 | printf("you wrote:%s\n",shared_memory); 20 | } 21 | 22 | -------------------------------------------------------------------------------- /shubham/Desktop/sai.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int shared=1; 5 | void *fun1(); 6 | void *fun2(); 7 | int main() 8 | { 9 | pthread_t t1,t2; 10 | pthread_create(&t1,NULL,&fun1,NULL); 11 | pthread_create(&t2,NULL,&fun2,NULL); 12 | pthread_join(t1,NULL); 13 | 14 | pthread_join(t2,NULL); 15 | printf("%d shared value is",shared); 16 | 17 | } 18 | void *fun1() 19 | { 20 | int x; 21 | x=shared; 22 | x=x+1; 23 | sleep(1); 24 | shared=x; 25 | } 26 | void *fun2() 27 | { 28 | int y; 29 | y=shared; 30 | y=y-1; 31 | sleep(1); 32 | shared=y; 33 | } 34 | 35 | -------------------------------------------------------------------------------- /shubham/Desktop/fun.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | void *fun1(); 5 | void *fun2(); 6 | int shared=1; 7 | int main() 8 | { 9 | pthread_t thread1,thread2; 10 | pthread_create(&thread1,NULL,fun1,NULL); 11 | pthread_create(&thread2,NULL,fun2,NULL); 12 | pthread_join(thread1,NULL); 13 | pthread_join(thread2,NULL); 14 | printf("Value of shared is %d",shared); 15 | } 16 | void *fun1() 17 | { 18 | int x; 19 | x=shared; 20 | x++; 21 | sleep(1); 22 | shared=x; 23 | } 24 | void *fun2() 25 | { 26 | int y; 27 | y=shared; 28 | y--; 29 | sleep(1); 30 | shared=y; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /ca2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | void *th_function1(); 4 | void *th_function2(); 5 | int shared=5; 6 | int main() 7 | { 8 | pthread_t thread1,thread2; 9 | pthread_create(&thread1,NULL,th_function1,NULL); 10 | pthread_create(&thread2,NULL,th_function2,NULL); 11 | pthread_join(thread1,NULL); 12 | pthread_join(thread2,NULL); 13 | printf("value of shared %d\n",shared); 14 | } 15 | void *th_function1() 16 | { 17 | int x; 18 | x=shared; 19 | x++; 20 | sleep(1); 21 | shared=x; 22 | } 23 | void *th_function2() 24 | { 25 | int y; 26 | y=shared; 27 | y--; 28 | sleep(1); 29 | shared=y; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /lpu/ca2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | void *th_function1(); 4 | void *th_function2(); 5 | int shared=5; 6 | int main() 7 | { 8 | pthread_t thread1,thread2; 9 | pthread_create(&thread1,NULL,th_function1,NULL); 10 | pthread_create(&thread2,NULL,th_function2,NULL); 11 | pthread_join(thread1,NULL); 12 | pthread_join(thread2,NULL); 13 | printf("value of shared %d\n",shared); 14 | } 15 | void *th_function1() 16 | { 17 | int x; 18 | x=shared; 19 | x++; 20 | sleep(1); 21 | shared=x; 22 | } 23 | void *th_function2() 24 | { 25 | int y; 26 | y=shared; 27 | y--; 28 | sleep(1); 29 | shared=y; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /sha/lab1.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | int main(int a,char *av[]) 7 | { 8 | int f1,f2,n,err; 9 | unsigned char buffer[4096]; 10 | char *f1path,f2path; 11 | if( a !=3) 12 | { 13 | printf("wrong argument count.\n"); 14 | exit(1); 15 | } 16 | 17 | f1path =av[1]; 18 | f2path= av[2]; 19 | 20 | f1=Open(f1path,O_RDONLY); 21 | f2=open(f2path,O_CREAT| O_WRONLY); 22 | 23 | while(1) 24 | { 25 | err=read(f1,buffer,4096); 26 | if(err=-1) 27 | { 28 | printf("error file reading.\n\n"); 29 | } 30 | else 31 | 32 | 33 | } 34 | 35 | 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | -------------------------------------------------------------------------------- /shredmem.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | int main() 7 | { 8 | int i; 9 | void *shared_memory; 10 | char buff[100]; 11 | int shmid; 12 | shmid=shmget((key_t)2345,1000,0666); 13 | printf("key of shared memory is %d\n",shmid); 14 | shared_memory=shmat(shmid,NULL,0); 15 | printf("process attached at %X\n",(int)shared_memory); 16 | printf("Enter some data to write to shared memory\n"); 17 | read(0,buff,100); 18 | strcpy(shared_memory,buff); 19 | printf("you wrote:%s\n",shared_memory); 20 | printf("Enter some data to write to shared memory\n"); 21 | read(0,buff,100); 22 | strcpy(shared_memory,buff); 23 | printf("you wrote:%s\n",shared_memory); 24 | } 25 | 26 | -------------------------------------------------------------------------------- /lpu/shredmem.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | int main() 7 | { 8 | int i; 9 | void *shared_memory; 10 | char buff[100]; 11 | int shmid; 12 | shmid=shmget((key_t)2345,1000,0666); 13 | printf("key of shared memory is %d\n",shmid); 14 | shared_memory=shmat(shmid,NULL,0); 15 | printf("process attached at %X\n",(int)shared_memory); 16 | printf("Enter some data to write to shared memory\n"); 17 | read(0,buff,100); 18 | strcpy(shared_memory,buff); 19 | printf("you wrote:%s\n",shared_memory); 20 | printf("Enter some data to write to shared memory\n"); 21 | read(0,buff,100); 22 | strcpy(shared_memory,buff); 23 | printf("you wrote:%s\n",shared_memory); 24 | } 25 | 26 | -------------------------------------------------------------------------------- /shubham/Desktop/sai.c.save: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int shared=1; 5 | void *fun1(); 6 | void *fun2(); 7 | pthread_mutex_t l; 8 | int main() 9 | { 10 | pthread_t t1,t2; 11 | pthread_create(&t1,NULL,&fun1,NULL); 12 | pthread_create(&t2,NULL,&fun2,NULL); 13 | pthread_join(t1,NULL); 14 | 15 | pthread_join(t2,NULL); 16 | printf("%d shared value is",shared); 17 | 18 | } 19 | void *fun1() 20 | { 21 | int x; 22 | pthread_mutex_lock(&l); 23 | x=shared; 24 | x=x+1; 25 | sleep(1); 26 | shared=x; 27 | pthread_mutex_unlock(&l); 28 | }pthread_mutex_unlo 29 | void *fun2() 30 | { 31 | int y; 32 | pthread_mutex_lock(&l); 33 | y=shared; 34 | y=y-1; 35 | sleep(1); 36 | shared=y; 37 | pthread_mutex_unlock 38 | } 39 | 40 | -------------------------------------------------------------------------------- /shubham/Desktop/semaphore.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | void *fun1(); 6 | void *fun2(); 7 | int shared=1; 8 | sem_t s; 9 | int main() 10 | { 11 | sem_init(&s,0,1); 12 | pthread_t thread1,thread2; 13 | pthread_create(&thread1,NULL,fun1,NULL); 14 | pthread_create(&thread2,NULL,fun2,NULL); 15 | pthread_join(thread1,NULL); 16 | pthread_join(thread2,NULL); 17 | printf("Final value of shared is %d",shared); 18 | } 19 | void *fun1() 20 | { 21 | int x; 22 | sem_wait(&s); 23 | x=shared; 24 | x++; 25 | sleep(1); 26 | shared=x; 27 | sem_post(&s); 28 | } 29 | void *fun2() 30 | { 31 | int y; 32 | sem_wait(&s); 33 | y=shared; 34 | y--; 35 | sleep(1); 36 | shared=y; 37 | sem_post(&s); 38 | } 39 | 40 | -------------------------------------------------------------------------------- /mutex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | void *func1(); 5 | void *func2(); 6 | int shared=1; 7 | pthread_mutex_tlock; 8 | int main() 9 | { 10 | pthread_mutex_init(&lock,NULL); 11 | pthread_t th1,th2; 12 | 13 | pthread_create(&th1,NULL,&func1,NULL); 14 | pthread_create(&th2,NULL,&func2,NULL); 15 | 16 | pthread_join(th1,NULL); 17 | pthread_join(th2,NULL); 18 | 19 | printf("final value of shared: %d\n",shared); 20 | } 21 | void *func1() 22 | { 23 | int x; 24 | pthread_mutex_lock(&lock); 25 | x=shared; 26 | x++; 27 | sleep(1); 28 | shared=x; 29 | pthread_mutex_unlock(&lock); 30 | } 31 | void *func2() 32 | { 33 | int y; 34 | pthread_mutex_lock(&lock); 35 | y=shared; 36 | y--; 37 | sleep(1); 38 | shared=y; 39 | pthread_mutex_unlock(&lock); 40 | } 41 | -------------------------------------------------------------------------------- /shubham/Desktop/ct.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | void *thread_function(void *arg); 6 | char message[]="WELCOME TO MY WORLD"; 7 | int main() 8 | { 9 | pid_t p; 10 | p=fork(); 11 | switch(p) 12 | { 13 | case 1: 14 | printf("\n error"); 15 | break; 16 | case 0: 17 | printf("\n child c1 is executing %d",getppid()); 18 | fork(); 19 | printf("\n child c11 is executing %d",getppid()); 20 | } 21 | } 22 | { 23 | int res; 24 | pthread_t a_thread; 25 | void *thread_result; 26 | res=pthread_create(&a_thread,NULL,thread_function,(void*)message); 27 | if(res!=0) 28 | { 29 | perror("thread creation failed"); 30 | exit(EXIT_FAILURE); 31 | } 32 | printf("hello world \n"); 33 | res=pthread_join(a_thread,&thread_result); 34 | } 35 | -------------------------------------------------------------------------------- /shubham/Desktop/mutex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | void *fun1(); 5 | void *fun2(); 6 | int shared=1; 7 | pthread_mutex_t l; 8 | int main() 9 | { 10 | pthread_mutex_init(&l,NULL); 11 | pthread_t thread1,thread2; 12 | pthread_create(&thread1,NULL,fun1,NULL); 13 | pthread_create(&thread2,NULL,fun2,NULL); 14 | pthread_join(thread1,NULL); 15 | pthread_join(thread2,NULL); 16 | printf("Value of shared is %d",shared); 17 | } 18 | void *fun1() 19 | { 20 | int x; 21 | pthread_mutex_lock(&l); 22 | x=shared; 23 | x++; 24 | sleep(1); 25 | shared=x; 26 | pthread_mutex_unlock(&l); 27 | } 28 | void *fun2() 29 | { 30 | int y; 31 | pthread_mutex_lock(&l); 32 | y=shared; 33 | y--; 34 | sleep(1); 35 | shared=y; 36 | pthread_mutex_unlock(&l); 37 | } 38 | 39 | -------------------------------------------------------------------------------- /lpu/mutex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | void *func1(); 5 | void *func2(); 6 | int shared=1; 7 | pthread_mutex_tlock; 8 | int main() 9 | { 10 | pthread_mutex_init(&lock,NULL); 11 | pthread_t th1,th2; 12 | 13 | pthread_create(&th1,NULL,&func1,NULL); 14 | pthread_create(&th2,NULL,&func2,NULL); 15 | 16 | pthread_join(th1,NULL); 17 | pthread_join(th2,NULL); 18 | 19 | printf("final value of shared: %d\n",shared); 20 | } 21 | void *func1() 22 | { 23 | int x; 24 | pthread_mutex_lock(&lock); 25 | x=shared; 26 | x++; 27 | sleep(1); 28 | shared=x; 29 | pthread_mutex_unlock(&lock); 30 | } 31 | void *func2() 32 | { 33 | int y; 34 | pthread_mutex_lock(&lock); 35 | y=shared; 36 | y--; 37 | sleep(1); 38 | shared=y; 39 | pthread_mutex_unlock(&lock); 40 | } 41 | -------------------------------------------------------------------------------- /linked.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | int f[50],st,len,j,k,a,c,p,i; 6 | for(i=0;i<50;i++) 7 | f[i]=0; 8 | printf("enter how many blovks already allocated"); 9 | scanf("%d",&p); 10 | printf("enter how many blocks allocated"); 11 | for(i=0;i 2 | #include 3 | int main() 4 | { 5 | int f[50],st,len,j,k,a,c,p,i; 6 | for(i=0;i<50;i++) 7 | f[i]=0; 8 | printf("enter how many blovks already allocated"); 9 | scanf("%d",&p); 10 | printf("enter how many blocks allocated"); 11 | for(i=0;i 2 | #include 3 | int f[50],i,j,k,inde[50],n,c,count=0,p; 4 | int main() 5 | { 6 | 7 | for(i=0;i<50;i++) 8 | f[i]=1; 9 | X: 10 | 11 | printf("Enter the index block\t"); 12 | scanf("%d",&p); 13 | if(f[p]==1) 14 | { 15 | f[p]=0; 16 | printf("\n Enter no of files on index block\t"); 17 | scanf("%d",&n); 18 | } 19 | else 20 | { 21 | printf("block already allocated\n"); 22 | goto X; 23 | } 24 | for(i=0;i%d:%d,p,inde[k],f[inde[k]]"); 39 | printf("enter 1 to more files and 0 to exit\t"); 40 | scanf("%d",&c); 41 | if(c==1) 42 | goto X; 43 | else 44 | exit(0); 45 | } 46 | 47 | -------------------------------------------------------------------------------- /lpu/index.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int f[50],i,j,k,inde[50],n,c,count=0,p; 4 | int main() 5 | { 6 | 7 | for(i=0;i<50;i++) 8 | f[i]=1; 9 | X: 10 | 11 | printf("Enter the index block\t"); 12 | scanf("%d",&p); 13 | if(f[p]==1) 14 | { 15 | f[p]=0; 16 | printf("\n Enter no of files on index block\t"); 17 | scanf("%d",&n); 18 | } 19 | else 20 | { 21 | printf("block already allocated\n"); 22 | goto X; 23 | } 24 | for(i=0;i%d:%d,p,inde[k],f[inde[k]]"); 39 | printf("enter 1 to more files and 0 to exit\t"); 40 | scanf("%d",&c); 41 | if(c==1) 42 | goto X; 43 | else 44 | exit(0); 45 | } 46 | 47 | -------------------------------------------------------------------------------- /caa.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | void main() 4 | { 5 | int f[50],index[50],i,n,len,j,c,k,p,count=0; 6 | for(i=0;i<50;i++) 7 | { 8 | f[i]=1; 9 | } 10 | x: 11 | printf("enter the index blocks"); 12 | scanf("%d",&p); 13 | if(f[p]=1) 14 | { 15 | f[p]=0; 16 | printf("enter no. of files in the index block"); 17 | scanf("%d",&n); 18 | } 19 | else 20 | { 21 | printf("\nblock is already allocated"); 22 | goto x; 23 | } 24 | for(i=0;i %d:%d",p,index[k],f[index[k]]); 38 | printf("press 1 to enter more files and 0 to exit"); 39 | scanf("%d",&c); 40 | if(c==1) 41 | goto x; 42 | else 43 | exit(0); 44 | } 45 | 46 | -------------------------------------------------------------------------------- /lpu/caa.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | void main() 4 | { 5 | int f[50],index[50],i,n,len,j,c,k,p,count=0; 6 | for(i=0;i<50;i++) 7 | { 8 | f[i]=1; 9 | } 10 | x: 11 | printf("enter the index blocks"); 12 | scanf("%d",&p); 13 | if(f[p]=1) 14 | { 15 | f[p]=0; 16 | printf("enter no. of files in the index block"); 17 | scanf("%d",&n); 18 | } 19 | else 20 | { 21 | printf("\nblock is already allocated"); 22 | goto x; 23 | } 24 | for(i=0;i %d:%d",p,index[k],f[index[k]]); 38 | printf("press 1 to enter more files and 0 to exit"); 39 | scanf("%d",&c); 40 | if(c==1) 41 | goto x; 42 | else 43 | exit(0); 44 | } 45 | 46 | -------------------------------------------------------------------------------- /shubham/processsync.c: -------------------------------------------------------------------------------- 1 | // process sync 2 | 3 | #include 4 | #include 5 | 6 | pthread_t t1,t2; 7 | pthread_mutex_t l1; 8 | 9 | int count=5; 10 | 11 | void *func1() 12 | { 13 | int b = count; 14 | pthread_mutex_lock(&l1); 15 | 16 | b = b+1; 17 | sleep(10); 18 | count = b; 19 | pthread_mutex_unlock(&l1); 20 | printf("b in func 1: %d\n",count); 21 | pthread_exit(b); 22 | } 23 | 24 | void *func2() 25 | { 26 | int b = count; 27 | pthread_mutex_lock(&l1); //spinlock 28 | 29 | b = b-1; 30 | count = b; 31 | pthread_mutex_unlock(&l1); 32 | printf("b in func2: %d\n",count); 33 | pthread_exit(b); 34 | } 35 | 36 | int main() 37 | { 38 | pthread_create(t1,NULL,func1,NULL); 39 | pthread_create(t1,NULL,func2,NULL); 40 | int a; 41 | int c; 42 | pthread_join(t1,&a); 43 | prinf("value returned by func1: %d\n",a); 44 | pthread_join(t2,&c); 45 | printf("value returned by func1: %d\n",c); 46 | } 47 | 48 | -------------------------------------------------------------------------------- /shubham/Desktop/thread.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | void *thread_function(void *arg); 7 | char message[]="WELCOME TO MY WORLD"; 8 | int main() 9 | { 10 | int res; 11 | pthread_t a_thread; 12 | void *thread_result; 13 | res=pthread_create(&a_thread,NULL, 14 | thread_function,(void*)message); 15 | if(res!=0) 16 | { 17 | perror("thread creation failed"); 18 | exit(EXIT_FAILURE); 19 | } 20 | printf("waiting for thread to finish\n"); 21 | res=pthread_join(a_thread,&thread_result); 22 | if(res!=0) 23 | { 24 | perror("thread joined failed"); 25 | exit(EXIT_FAILURE); 26 | } 27 | printf("thread joined,it returned%s\n",(char*)thread_result); 28 | printf("message is now%s\n",message); 29 | exit(EXIT_FAILURE); 30 | } 31 | void *thread_function(void *arg) 32 | { 33 | printf("thread f_function is running.argument was%s\n",(char*)arg); 34 | sleep(3); 35 | strcpy(message,"BYE"); 36 | pthread_exit("thankyou for the cpu time"); 37 | } 38 | -------------------------------------------------------------------------------- /semreadwite.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | void *reader(); 6 | void*writer(); 7 | int f[100],n; 8 | sem_t s; 9 | int main() 10 | { 11 | sem_int(&s,0,1`); 12 | pthread_t thread1,thread2; 13 | pthread_create(&thread1,NULL,reader,NULL); 14 | pthread_create(&thread2,NULL,writer,NULL); 15 | pthread_join(thread1,NULL); 16 | pthread_join(thread2,NULL); 17 | } 18 | void *reader() 19 | { 20 | sem_wait(&s); 21 | printf("enter number of elements in ana array"); 22 | scanf("%d",&n); 23 | for(int i=0;i 2 | #include 3 | #include 4 | #include 5 | void *reader(); 6 | void*writer(); 7 | int f[100],n; 8 | sem_t s; 9 | int main() 10 | { 11 | sem_int(&s,0,1`); 12 | pthread_t thread1,thread2; 13 | pthread_create(&thread1,NULL,reader,NULL); 14 | pthread_create(&thread2,NULL,writer,NULL); 15 | pthread_join(thread1,NULL); 16 | pthread_join(thread2,NULL); 17 | } 18 | void *reader() 19 | { 20 | sem_wait(&s); 21 | printf("enter number of elements in ana array"); 22 | scanf("%d",&n); 23 | for(int i=0;i 2 | #include 3 | #include 4 | 5 | sem_t mutex,writeblock; 6 | int data = 0,rcount = 0; 7 | 8 | void *reader(void *arg) 9 | { 10 | int f; 11 | f = ((int)arg); 12 | sem_wait(&mutex); 13 | rcount = rcount + 1; 14 | if(rcount==1) 15 | sem_wait(&writeblock); 16 | sem_post(&mutex); 17 | printf("Data read by the reader%d is %d\n",f,data); 18 | sleep(1); 19 | sem_wait(&mutex); 20 | rcount = rcount - 1; 21 | if(rcount==0) 22 | sem_post(&writeblock); 23 | sem_post(&mutex); 24 | } 25 | 26 | void *writer(void *arg) 27 | { 28 | int f; 29 | f = ((int) arg); 30 | sem_wait(&writeblock); 31 | data++; 32 | printf("Data writen by the writer%d is %d\n",f,data); 33 | sleep(1); 34 | sem_post(&writeblock); 35 | } 36 | 37 | int main() 38 | { 39 | int i,b; 40 | pthread_t rtid[5],wtid[5]; 41 | sem_init(&mutex,0,1); 42 | sem_init(&writeblock,0,1); 43 | for(i=0;i<=3;i++) 44 | { 45 | pthread_create(&wtid[i],NULL,writer,(void *)i); 46 | pthread_create(&rtid[i],NULL,reader,(void *)i); 47 | } 48 | for(i=0;i<=2;i++) 49 | { 50 | pthread_join(wtid[i],NULL); 51 | pthread_join(rtid[i],NULL); 52 | } 53 | return 0; 54 | } -------------------------------------------------------------------------------- /shubham/Desktop/prod.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #define size 10 5 | //pthread_mutex_t mutex; 6 | pthread_t tidP[20],tidC[20]; 7 | sem_t full,empty,mutex,e; 8 | int counter=0; 9 | int buffer[size]; 10 | 11 | void initialize() 12 | { 13 | 14 | counter=0; 15 | } 16 | 17 | void write(int item) 18 | { 19 | buffer[counter++]=item; 20 | } 21 | 22 | int read() 23 | { 24 | 25 | return(buffer[--counter]); 26 | } 27 | 28 | void * producer (void *param) 29 | { 30 | int item,i; 31 | item=rand()%5; // 32 | sem_wait(&empty); 33 | sem_wait(&mutex); 34 | printf("\nProducer has produced item: %d\n",item); 35 | write(item); 36 | sem_post(&mutex); 37 | sem_post(&full); 38 | } 39 | 40 | void * consumer (void * param) 41 | { 42 | int item; 43 | sem_wait(&full); 44 | sem_wait(&mutex); 45 | item=read(); 46 | printf("\nConsumer has consumed item: %d\n",item); 47 | sem_post(&mutex); 48 | sem_post(&empty); 49 | } 50 | 51 | int main() 52 | { 53 | int n1=1,n2=2,i; 54 | sem_init(&mutex,0,1); 55 | sem_init(&full,1,0); 56 | sem_init(&empty,1,n1); 57 | sem_init(&e,1,0); 58 | for(i=0;i