From 0fe7451cd9f47c0f01d6f71a7aef09a2fae10226 Mon Sep 17 00:00:00 2001 From: zeus Date: Wed, 24 Mar 2021 15:41:28 +0200 Subject: [PATCH] pipes --- .../sec/project/courses/pipes/makefifo.sh | 5 ++ .../sec/project/courses/pipes/par-from-ch | Bin 0 -> 8656 bytes .../sec/project/courses/pipes/par-from-ch.c | 28 +++++++++ .../swarmlab.io/sec/project/courses/pipes/rf | Bin 0 -> 8640 bytes .../sec/project/courses/pipes/rf.c | 41 +++++++++++++ .../sec/project/courses/pipes/shell-pipe.sh | 7 +++ .../sec/project/courses/pipes/shell-pipe1.sh | 7 +++ .../sec/project/courses/pipes/shell-pipe2.sh | 7 +++ .../swarmlab.io/sec/project/courses/pipes/wf | Bin 0 -> 8640 bytes .../sec/project/courses/pipes/wf.c | 49 +++++++++++++++ .../courses/pthread/CreationTermination | Bin 0 -> 8512 bytes .../courses/pthread/CreationTermination.c | 57 ++++++++++++++++++ .../courses/pthread/CreationTermination.c.sh | 1 + .../courses/pthread/CreationTermination1 | Bin 0 -> 12928 bytes .../courses/pthread/CreationTermination1.c | 57 ++++++++++++++++++ .../courses/pthread/CreationTermination1.c.sh | 1 + 16 files changed, 260 insertions(+) create mode 100755 install/usr/share/swarmlab.io/sec/project/courses/pipes/makefifo.sh create mode 100755 install/usr/share/swarmlab.io/sec/project/courses/pipes/par-from-ch create mode 100644 install/usr/share/swarmlab.io/sec/project/courses/pipes/par-from-ch.c create mode 100755 install/usr/share/swarmlab.io/sec/project/courses/pipes/rf create mode 100644 install/usr/share/swarmlab.io/sec/project/courses/pipes/rf.c create mode 100755 install/usr/share/swarmlab.io/sec/project/courses/pipes/shell-pipe.sh create mode 100755 install/usr/share/swarmlab.io/sec/project/courses/pipes/shell-pipe1.sh create mode 100755 install/usr/share/swarmlab.io/sec/project/courses/pipes/shell-pipe2.sh create mode 100755 install/usr/share/swarmlab.io/sec/project/courses/pipes/wf create mode 100644 install/usr/share/swarmlab.io/sec/project/courses/pipes/wf.c create mode 100755 install/usr/share/swarmlab.io/sec/project/courses/pthread/CreationTermination create mode 100644 install/usr/share/swarmlab.io/sec/project/courses/pthread/CreationTermination.c create mode 100755 install/usr/share/swarmlab.io/sec/project/courses/pthread/CreationTermination.c.sh create mode 100755 install/usr/share/swarmlab.io/sec/project/courses/pthread/CreationTermination1 create mode 100644 install/usr/share/swarmlab.io/sec/project/courses/pthread/CreationTermination1.c create mode 100755 install/usr/share/swarmlab.io/sec/project/courses/pthread/CreationTermination1.c.sh diff --git a/install/usr/share/swarmlab.io/sec/project/courses/pipes/makefifo.sh b/install/usr/share/swarmlab.io/sec/project/courses/pipes/makefifo.sh new file mode 100755 index 0000000..93fd6d4 --- /dev/null +++ b/install/usr/share/swarmlab.io/sec/project/courses/pipes/makefifo.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +fifo=/tmp/testpipe +rm -f $fifo +mkfifo -m a=rw $fifo diff --git a/install/usr/share/swarmlab.io/sec/project/courses/pipes/par-from-ch b/install/usr/share/swarmlab.io/sec/project/courses/pipes/par-from-ch new file mode 100755 index 0000000000000000000000000000000000000000..c38bd3837ff3a866358c1e34958e45732805366e GIT binary patch literal 8656 zcmeHMYitzP6~61m4<24`csh`Vfj|VbUTiSNkhpk_*Nh_@T*s!38W`5zS$oC4x;xuo z8nteL$XjD-wfTW6wL-1b(EO-q6)6y@sx4ERG*U#QJ|eZ1plTwU5Y;V#(g$qMxpU5X zX1rSxsXueA*>lf#9``Z#-Z}U9Yk`io5|>MGaf{Cin}EE>f^`2Cc4 zM3e!)Kw_r6*(4w}%UyEKw1RLqP_%0-F##uig!Gtl50RFVtPoKbnY zvOpDCVS1MOagHe4A&Yk7WH(NBOlPTMOnH1bHhg->pOdzN3=31##nSbz5t8*qCNCWH zNrIWO-RHm#`}t9emlV6Hy<+n+O#Np{!xdYjk-modth9a$D_g?%%~OkgUJegpDF6G{%eShz_rG%M)$^BbCU0-iCm(wWZTW%fM=sBU zrcyxr2w+PK;59|?6-DsJi{QJ8;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MoBM9HpT)xh%J&`4xm{C=v3p_rGjs*M&x%By_WuO{L;{Nd literal 0 HcmV?d00001 diff --git a/install/usr/share/swarmlab.io/sec/project/courses/pipes/par-from-ch.c b/install/usr/share/swarmlab.io/sec/project/courses/pipes/par-from-ch.c new file mode 100644 index 0000000..199faed --- /dev/null +++ b/install/usr/share/swarmlab.io/sec/project/courses/pipes/par-from-ch.c @@ -0,0 +1,28 @@ +#include +#include +#include +#include +#include +#include + + +char *phrase = "My child sent me this!!"; + +int main() +{ + int fd[2], bytesread; + char message[100]; + + pipe(fd); + + if (fork()==0) { + close(fd[0]); + write (fd[1],phrase,strlen(phrase)+1); + close(fd[1]); + } else { + close(fd[1]); + bytesread=read(fd[0],message,100); + printf("Read %d bytes:%s\n", bytesread, message); + close(fd[0]); + } +} diff --git a/install/usr/share/swarmlab.io/sec/project/courses/pipes/rf b/install/usr/share/swarmlab.io/sec/project/courses/pipes/rf new file mode 100755 index 0000000000000000000000000000000000000000..c3a7efcc0921d82b3042a2028e4a194cfc7db238 GIT binary patch literal 8640 zcmeHMYitzP6~61m4}w`Q1c(DEY$>iFiPtvaVUo~z{bJmjN5Q5q%w+8y+bi~A?amV0 zs!|7sC>z&_6{QkIs${j5nm&G{Rn*X^N{vjQ`BQ<^s#K&csQ}q&qEaOxG%dK_xpR+q zX1v=}Re$ELX3jm|J?Gr_opaBAqouvI$m0>5yyA0$xPej&X;1|tt5pW1LDY-Icz;UV zBTB$8l9*NAU=fsB>83Kxv`pb%P|~X}vH&-|N69he77{I1W% z7tn_-STJS1FG7#n`QIkL65OxqD>N=6s{Kq=cSTJs+P!T{O)OF!izYII)r0lhs<&+k zrjxvMboB{>e$^BOD2qtaCgjreqTJ9Q2M$hnpcoIP~`eq ztB_DDc?A80;Kh_#9bHT^J*u3~2Oft3m3dm71B}#NkQQl=Qhl5*+i-Q{ z%Ay$?u8snUU$^1qYy|YC4Od5%EaiEmGt+02KcVEQP96&?p0we#KRLZ(-h2}m;85$ry-b~lKe^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ztHu7cQ)PA>}2=IVSjhlXxfGetpQ>pNf zZY0dqkmyZ?y3`$M~1^p-u%Is#fwsff^pc4mvRz7j!}tFLWXcVuQ|N8Etezm^ZY-iUz6(qg%ikF4QCG zq~0G+L@1QlwilWRXX=@>fq~AA5ls~M?sS?>Q=pQfnr`ceP4dK1&@yi%(isSKS`fkX zP}~f6gPJLe_Hzy)RwFeaf{CPQ1VfE&)n>R)aeawQusah)06rQKLE`$u>3$K63?*RC zqGrk}IclWR(PYBG=qO7Wu`ns9+(66}LD}&jvcbM2SkoB9n^ri4l5)a>M!#Cq{Sg>p z&Qi4&x23^()DVtGd(b9YFF}l{2x4Q!u~}?8_kYXMeFsMqzWr8Wf0HTScT};IY?SII%w8mkt7>yAA8J-^`Tnc@U9_Y}nIbFm#7vefF=J@_mfk&vHzU zK%eep%+LGbN+F;sbGKi?Vi*}3Q`TpHovG!=mu=Qk!o-#CRSea}@t-%ptG{ha09{r{oT=W5tbVaoB0Li#^->GOSu>BFq3sJs4Ox%By7 z#I(${;CbBG>>J3?9fRWo>__wescw1Znf?yC6*hgoXFaU~JuC+inV4t#7EoGyTtDB( z`2TADUz*n^>+w3G`v`TB^+zfK-~{e(l86zD%)eQm>Dwr=>(BeKssgTu4X_^b*O4KN z>u3MZUqIh&?*r&k{k3@PiS;+xLF7r6lAZF}vr4RYgR1C7HE^^J$>-(v^Z7~Zo7-+_ fTJIS;ERasRjB~wKDf#C4^^d8m?`;-T)UE$-kq#4r literal 0 HcmV?d00001 diff --git a/install/usr/share/swarmlab.io/sec/project/courses/pipes/rf.c b/install/usr/share/swarmlab.io/sec/project/courses/pipes/rf.c new file mode 100644 index 0000000..e58809a --- /dev/null +++ b/install/usr/share/swarmlab.io/sec/project/courses/pipes/rf.c @@ -0,0 +1,41 @@ +#include +#include +#include +#include +#include +#include + +// C program to implement one side of FIFO +// This side reads first, then writes +int main() +{ + int fd1; + + // FIFO file path + char * myfifo = "/tmp/myfifo"; + + // Creating the named file(FIFO) + // mkfifo(,) + mkfifo(myfifo, 0666); + + char str1[80], str2[80]; + while (1) + { + // First open in read only and read + fd1 = open(myfifo,O_RDONLY); + read(fd1, str1, 80); + + // Print the read string and close + printf("User1: %s\n", str1); + close(fd1); + + // Now open in write mode and write + // string taken from user. + fd1 = open(myfifo,O_WRONLY); + fgets(str2, 80, stdin); + write(fd1, str2, strlen(str2)+1); + close(fd1); + } + return 0; +} + diff --git a/install/usr/share/swarmlab.io/sec/project/courses/pipes/shell-pipe.sh b/install/usr/share/swarmlab.io/sec/project/courses/pipes/shell-pipe.sh new file mode 100755 index 0000000..c79dcf6 --- /dev/null +++ b/install/usr/share/swarmlab.io/sec/project/courses/pipes/shell-pipe.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +for i in `seq 10 30`; do + echo $i + sleep 1 +done > /tmp/testpipe + diff --git a/install/usr/share/swarmlab.io/sec/project/courses/pipes/shell-pipe1.sh b/install/usr/share/swarmlab.io/sec/project/courses/pipes/shell-pipe1.sh new file mode 100755 index 0000000..0d10fba --- /dev/null +++ b/install/usr/share/swarmlab.io/sec/project/courses/pipes/shell-pipe1.sh @@ -0,0 +1,7 @@ +#!/bin/sh + + +for i in `seq 10 30`; do + echo "allo programma: $i " + sleep 1 +done > /tmp/testpipe diff --git a/install/usr/share/swarmlab.io/sec/project/courses/pipes/shell-pipe2.sh b/install/usr/share/swarmlab.io/sec/project/courses/pipes/shell-pipe2.sh new file mode 100755 index 0000000..9f536d6 --- /dev/null +++ b/install/usr/share/swarmlab.io/sec/project/courses/pipes/shell-pipe2.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +for i in `seq 10 30`; do + echo $i > /tmp/testpipe + sleep 1 +done + diff --git a/install/usr/share/swarmlab.io/sec/project/courses/pipes/wf b/install/usr/share/swarmlab.io/sec/project/courses/pipes/wf new file mode 100755 index 0000000000000000000000000000000000000000..71c04d36707cccbb85482a72a66949c7a54e7501 GIT binary patch literal 8640 zcmeHMYitzP6~61Wv3ac*0>nUCwiH)D;`qg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$E4PWFi~(bPx>Pp;({&Yo>f3Oy>f}O3Ck{Uw7%>ul!u5++L+N*M7z=|1#fxzIQNv zk_XmRFWdXJtA4(pFy;F>%e(vkU8T>}u%E)zy?@>MKXU2weTV5iT(P2V{hzz^`Ci1d z!nNRe+}P|dk)b;V#|PMt=KoXO^2{^+Ep#hw`h3rNLLTlBD+AyJ?r)NatVQPDtk3ifl-Tv>{8&{1*TV)_kNK;}5XSYh z|K~5F@3!|2bgBM2Jod!;o9rO+BumLodF@#x*1Jhn^t2i{`p%Hg%kAg$lh!x4-O{w) d({xxMopKrHdaY9O%?s-vQCHuaEU2hk|KH-l6qo=2 literal 0 HcmV?d00001 diff --git a/install/usr/share/swarmlab.io/sec/project/courses/pipes/wf.c b/install/usr/share/swarmlab.io/sec/project/courses/pipes/wf.c new file mode 100644 index 0000000..ce17aac --- /dev/null +++ b/install/usr/share/swarmlab.io/sec/project/courses/pipes/wf.c @@ -0,0 +1,49 @@ +#include +#include +#include +#include +#include +#include + +// C program to implement one side of FIFO +// This side writes first, then reads + +int main() +{ + int fd; + + // FIFO file path + char * myfifo = "/tmp/myfifo"; + + // Creating the named file(FIFO) + // mkfifo(, ) + mkfifo(myfifo, 0666); + + char arr1[80], arr2[80]; + while (1) + { + // Open FIFO for write only + fd = open(myfifo, O_WRONLY); + + // Take an input arr2ing from user. + // 80 is maximum length + fgets(arr2, 80, stdin); + + // Write the input arr2ing on FIFO + // and close it + write(fd, arr2, strlen(arr2)+1); + close(fd); + + // Open FIFO for Read only + fd = open(myfifo, O_RDONLY); + + // Read from FIFO + read(fd, arr1, sizeof(arr1)); + + // Print the read message + printf("User 2: %s\n", arr1); + close(fd); + } + return 0; +} + diff --git a/install/usr/share/swarmlab.io/sec/project/courses/pthread/CreationTermination b/install/usr/share/swarmlab.io/sec/project/courses/pthread/CreationTermination new file mode 100755 index 0000000000000000000000000000000000000000..2856dba888a2492ef73df7457373f305206a6579 GIT binary patch literal 8512 zcmeHMZ){uD6~B&~CWXc^g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wsnbu~5uexJ4a5QU zTbjoq%(CFqK7TpS3rc+@gy@1l^7+f(b-_oZV}0dHyr1~|<=!voKj!oBh`ahJ`%5u$ zZV}w=S~`N?|7Sjb|Nkw!FXKZxC*WW$Aasg6~1Q0*b7at z-fP;y<(u4b^mm5Nx>6t6KWKhS-M#)#&}M;j)E8XJb#m#fUfsWjubxX{$msX~7eq$x A!~g&Q literal 0 HcmV?d00001 diff --git a/install/usr/share/swarmlab.io/sec/project/courses/pthread/CreationTermination.c b/install/usr/share/swarmlab.io/sec/project/courses/pthread/CreationTermination.c new file mode 100644 index 0000000..9e2fc47 --- /dev/null +++ b/install/usr/share/swarmlab.io/sec/project/courses/pthread/CreationTermination.c @@ -0,0 +1,57 @@ +#include +#include +#include + +void *print_message_function( void *ptr ); + +int main() +{ + pthread_t thread1, thread2; + char *message1 = "Thread 1"; + char *message2 = "Thread 2"; + int iret1, iret2; + + /* Create independent threads each of which will execute function */ + + iret1 = pthread_create( &thread1, NULL, print_message_function, (void*) message1); + iret2 = pthread_create( &thread2, NULL, print_message_function, (void*) message2); + + /* + Arguments: + thread - returns the thread id. (unsigned long int defined in bits/pthreadtypes.h) + attr - Set to NULL if default thread attributes are used. + void * (*start_routine) - pointer to the function to be threaded. Function has a single argument: pointer to void. + *arg - pointer to argument of function. To pass multiple arguments, send a pointer to a structure. + + The following is a list of "thread attributes" and their default values + Attribute Default Meaning of default + contentionscope PTHREAD_SCOPE_PROCESS Thread will compete for resources within the process + detachstate PTHREAD_CREATE_JOINABLE Thread is joinable by other threads + stackaddr NULL Workspace (stack) used by thread is allocated (reserved) by the operating system + stacksize NULL Workspace size used by thread is determined by the operating system + priority 0 Priority of the thread (the lower the priority value, the higher the priority...) + policy SCHED_OTHER The scheduling policy is determined by the system + inheritsched PTHREAD_EXPLICIT_SCHED scheduling policy and parameters are not inherited but explicitly defined by the attribute object + guardsize PAGESIZE size of guard area for a thread's created stack (this area will help determine if the thread has exceeded the total amount of space that was allocated for the thread) + + See https://man7.org/linux/man-pages/man3/pthread_create.3.html + */ + + /* Wait till threads are complete before main continues. Unless we */ + /* wait we run the risk of executing an exit which will terminate */ + /* the process and all threads before the threads have completed. */ + + pthread_join( thread1, NULL); + pthread_join( thread2, NULL); + + printf("Thread 1 returns: %d\n",iret1); + printf("Thread 2 returns: %d\n",iret2); + pthread_exit(NULL); +} + +void *print_message_function( void *ptr ) +{ + char *message; + message = (char *) ptr; + printf("%s \n", message); +} diff --git a/install/usr/share/swarmlab.io/sec/project/courses/pthread/CreationTermination.c.sh b/install/usr/share/swarmlab.io/sec/project/courses/pthread/CreationTermination.c.sh new file mode 100755 index 0000000..8ef65ae --- /dev/null +++ b/install/usr/share/swarmlab.io/sec/project/courses/pthread/CreationTermination.c.sh @@ -0,0 +1 @@ +gcc -pthread -o CreationTermination CreationTermination.c diff --git a/install/usr/share/swarmlab.io/sec/project/courses/pthread/CreationTermination1 b/install/usr/share/swarmlab.io/sec/project/courses/pthread/CreationTermination1 new file mode 100755 index 0000000000000000000000000000000000000000..73424b4108421444d5bcc2b2adc7e481872594da GIT binary patch literal 12928 zcmeHNeQ;D)6~CKJN(f;I6j};JUQ?JtJ8TomN1(-KLlzzyC_-rMwDfhe`;u(CAL-k- z7;uVp(stNM)8a=RrnZVYI_>y}IAc5bhZe+wRmY*Dwi$~KXsby-#?)Fw6xQFl@1B>p zk6o)X{^ji5*>~>wosWC(x%b`o?tS+&(XI_Ofq>u?6dx7DO-yl+b|q-PL1jSNMVpw4 z>jH7LxD0%)#2k6MLm+k1IpvyZy~2Z_WY<>X0DgM4(qqasBwD9r<;cKv2W2XRCIPae zy7n)SET|?kOrKTt7*&+*h$Xv0WjCnomePuOeL13l9~MAvca}h%T}!j z=d$7DvfbpLbT@9&SWn7yWMw7F zg<(FBkEMjm4JK`uiK7hLblLl|$qW@9r(#!$fxMj)hLN*l@%xQ<|NTa9ED1+eGGq4w zj}OL--ee}0O759-kuy`hB4=BsWo0cWkvH;S*+x1B?;E=|b*wj*hgZ0{<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L{D=}mO8|}k}f4L<+0~ToNK%0 y(0X-0(Q}60*}48af6(~mx;qxmRlm-mfAcx#a#?pKGUe=Vz24Ed$cl>k?f(Tws?( +#include +#include +#include +#include + +pthread_t tid[2]; +int ret1,ret2; + +void* doSomeThing(void *arg) +{ + unsigned long i = 0; + pthread_t id = pthread_self(); + + for(i=0; i<(4294967295);i++); + + if(pthread_equal(id,tid[0])) + { + printf("\n First thread processing done\n"); + ret1 = 1; + pthread_exit(&ret1); + } + else + { + printf("\n Second thread processing done\n"); + ret2 = 2; + pthread_exit(&ret2); + } + + return NULL; +} + +int main(void) +{ + int i = 0; + int err; + int *ptr[2]; + + while(i < 2) + { + err = pthread_create(&(tid[i]), NULL, &doSomeThing, NULL); + if (err != 0) + printf("\ncan't create thread :[%s]", strerror(err)); + else + printf("\n Thread created successfully\n"); + + i++; + } + + pthread_join(tid[0], (void**)&(ptr[0])); + pthread_join(tid[1], (void**)&(ptr[1])); + + printf("\n return value from first thread is [%d]\n", *ptr[0]); + printf("\n return value from second thread is [%d]\n", *ptr[1]); + + return 0; +} diff --git a/install/usr/share/swarmlab.io/sec/project/courses/pthread/CreationTermination1.c.sh b/install/usr/share/swarmlab.io/sec/project/courses/pthread/CreationTermination1.c.sh new file mode 100755 index 0000000..5ef5258 --- /dev/null +++ b/install/usr/share/swarmlab.io/sec/project/courses/pthread/CreationTermination1.c.sh @@ -0,0 +1 @@ +gcc -pthread -o CreationTermination1 CreationTermination1.c