From 290a99e0ee224ebc7550c34a7096192d2201638c Mon Sep 17 00:00:00 2001 From: Kolan Sh Date: Sat, 9 Apr 2011 19:55:52 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=B8=D1=81=D1=85=D0=BE=D0=B4=D0=BD=D0=B8=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=BD=D0=B0=20c,=20cpp,=20java,=20nasm,=20perl,=20php?= =?UTF-8?q?,=20ruby,=20prolog,=20nasm?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bash/delunpack/delunpack.sh | 0 bash/delunpack/delunpack2.sh | 0 bash/delunpack/delunpack3.sh | 0 bash/delunpack/findunfiles.sh | 0 bash/delunpack/margin.sh | 0 bash/delunpack/mkbaselist.sh | 0 bash/delunpack/mkbaselist2.sh | 0 bash/gedit/geditmkrun.sh | 0 bash/gedit/geditxmkrun.sh | 0 bash/gedit/hello.sh | 0 bash/gprs/3Gconnect.sh | 0 bash/gprs/3Gdisconnect.sh | 0 bash/gprs/3Gmake_bug.sh | 0 bash/gprs/3Greconnect.sh | 0 bash/ld_symlinks/tmp3.sh | 0 bash/studyBash/bash_script.sh | 28 ++-- bash/studyBash/read_file.sh | 17 +++ c/12309/test12309.c | 85 ++++++++++++ c/5minLorTest/5min.c | 19 +++ c/5minLorTest/typical_errors_in_c.c | 12 ++ c/LebedevRebusy/koka_kola_voda.c | 39 ++++++ c/LebedevRebusy/koza_koza_stado.c | 52 ++++++++ c/LebedevRebusy/magnij_tantal_metally.c | 56 ++++++++ c/ParallelsTest/1.c | 18 +++ c/ParallelsTest/10.c | 34 +++++ c/ParallelsTest/4npipe.c | 67 ++++++++++ c/ParallelsTest/4unpipe.c | 65 +++++++++ c/ParallelsTest/6.c | 10 ++ c/ParallelsTest/77.c | 48 +++++++ c/ParallelsTest/ParallelsTest/1.c | 18 +++ c/ParallelsTest/ParallelsTest/10.c | 34 +++++ c/ParallelsTest/ParallelsTest/4npipe.c | 67 ++++++++++ c/ParallelsTest/ParallelsTest/4unpipe.c | 65 +++++++++ c/ParallelsTest/ParallelsTest/Answers.txt | 62 +++++++++ c/ParallelsTest/tmp.c | 10 ++ c/StShDinLibs/static/build.sh | 18 +++ c/StShDinLibs/static/demo_use.c | 6 + c/StShDinLibs/static/demo_use.o | Bin 0 -> 3104 bytes c/StShDinLibs/static/libhello-static.a | Bin 0 -> 3838 bytes c/StShDinLibs/static/libhello-static.o | Bin 0 -> 3616 bytes c/StShDinLibs/static/libhello.c | 6 + c/StShDinLibs/static/libhello.h | 1 + c/ToUpperTest/build | 1 + c/ToUpperTest/build.sh | 9 ++ c/ToUpperTest/main.c | 23 ++++ c/bigmalloc/bigmalloc.c | 20 +++ c/bigmalloc/bignew.cpp | 21 +++ c/getc/tmp2.c | 9 ++ c/glcube/molecule.c | 152 ++++++++++++++++++++++ c/stat/stattest.c | 12 ++ c/study/sigaction.c | 20 +++ cpp/21movSamokatAuto/main.cpp | 31 +++++ cpp/akk/akk.cpp | 14 ++ cpp/bookAmmeraal/00/main.cpp | 59 +++++++++ cpp/bookAmmeraal/01/main.cpp | 34 +++++ cpp/bookAmmeraal/02/main.cpp | 33 +++++ cpp/bookAmmeraal/03/main.cpp | 42 ++++++ cpp/bookAmmeraal/04/main.cpp | 32 +++++ cpp/bookAmmeraal/05/main.cpp | 32 +++++ cpp/bookAmmeraal/06/main.cpp | 37 ++++++ cpp/bookAmmeraal/07/main.cpp | 45 +++++++ cpp/bookAmmeraal/make_dirs.sh | 9 ++ cpp/gauss_miron/gauss.cpp | 64 +++++++++ cpp/gauss_miron/gauss_mir.cpp | 54 ++++++++ cpp/hello/hello.cpp | 9 ++ cpp/lu_solve/lu_solve.hpp | 61 +++++++++ cpp/lu_solve/main.cpp | 48 +++++++ cpp/multithreading/asynch.c | 43 ++++++ cpp/multithreading/dish_ment.c | 4 + cpp/multithreading/event.c | 82 ++++++++++++ cpp/multithreading/mutexes.c | 49 +++++++ cpp/multithreading/pthread_ex.c | 65 +++++++++ cpp/multithreading/pthread_ex.cpp | 61 +++++++++ cpp/multithreading/pthread_ex.geany | 43 ++++++ cpp/multithreading/pthread_ex.o | Bin 0 -> 14392 bytes cpp/multithreading/sem08-1a.c | 48 +++++++ cpp/multithreading/sem08-1b.c | 48 +++++++ cpp/multithreading/semabinit.c | 61 +++++++++ cpp/multithreading/time_test.c | 29 +++++ cpp/multithreading/time_test.o | Bin 0 -> 4952 bytes cpp/multithreading/tmp.c | 12 ++ cpp/multithreading/udp_socket.c | 62 +++++++++ cpp/sockets/echo-client.c | 62 +++++++++ cpp/sockets/echo-server.c | 65 +++++++++ cpp/sockets/int2ip.c | 33 +++++ cpp/sockets/ip2int.c | 30 +++++ cpp/sockets/sock1.c | 67 ++++++++++ cpp/sockets/tmp1.c | 25 ++++ cpp/wstring/wstring.cpp | 26 ++++ gtk/hello_world/build.sh | 1 + gtk/hello_world/hello_world | Bin 0 -> 12481 bytes gtk/hello_world/hello_world.c | 25 ++++ java/helloworld1/.classpath | 6 + java/helloworld1/.project | 17 +++ java/helloworld1/hello.class | Bin 0 -> 518 bytes java/helloworld1/hello.java | 6 + nasm/div/2.asm | 37 ++++++ nasm/div/2.c | 16 +++ nasm/div/2.o | Bin 0 -> 512 bytes nasm/div/build | 13 ++ nasm/fact/1 | Bin 0 -> 7969 bytes nasm/fact/1.asm | 26 ++++ nasm/fact/1.c | 16 +++ nasm/fact/1.o | Bin 0 -> 624 bytes nasm/fact/build.sh | 10 ++ nasm/flags/build.sh | 12 ++ nasm/flags/flags | Bin 0 -> 4145 bytes nasm/flags/flags.asm | 26 ++++ nasm/flags/flags.c | 16 +++ nasm/flags/flags.o | Bin 0 -> 464 bytes nasm/lnxhello/build.sh | 9 ++ nasm/lnxhello/lnxhello.asm | 49 +++++++ nasm/lnxhello/lnxhello.o | Bin 0 -> 768 bytes perl/ping.pl | 41 ++++++ perl/study0.pl | 111 ++++++++++++++++ php/ftrunc.php | 47 +++++++ php/strtotime | 1 + php/strtotime.php | 4 + prolog/parents.pl | 24 ++++ prolog/parents2.pl | 24 ++++ prolog/queens.pl | 96 ++++++++++++++ prolog/queens_fd.fd | 6 + python/akk.py | 6 + ruby/hello | 9 ++ 124 files changed, 3263 insertions(+), 14 deletions(-) mode change 100644 => 100755 bash/delunpack/delunpack.sh mode change 100644 => 100755 bash/delunpack/delunpack2.sh mode change 100644 => 100755 bash/delunpack/delunpack3.sh mode change 100644 => 100755 bash/delunpack/findunfiles.sh mode change 100644 => 100755 bash/delunpack/margin.sh mode change 100644 => 100755 bash/delunpack/mkbaselist.sh mode change 100644 => 100755 bash/delunpack/mkbaselist2.sh mode change 100644 => 100755 bash/gedit/geditmkrun.sh mode change 100644 => 100755 bash/gedit/geditxmkrun.sh mode change 100644 => 100755 bash/gedit/hello.sh mode change 100644 => 100755 bash/gprs/3Gconnect.sh mode change 100644 => 100755 bash/gprs/3Gdisconnect.sh mode change 100644 => 100755 bash/gprs/3Gmake_bug.sh mode change 100644 => 100755 bash/gprs/3Greconnect.sh mode change 100644 => 100755 bash/ld_symlinks/tmp3.sh mode change 100644 => 100755 bash/studyBash/bash_script.sh create mode 100755 bash/studyBash/read_file.sh create mode 100644 c/12309/test12309.c create mode 100644 c/5minLorTest/5min.c create mode 100644 c/5minLorTest/typical_errors_in_c.c create mode 100644 c/LebedevRebusy/koka_kola_voda.c create mode 100644 c/LebedevRebusy/koza_koza_stado.c create mode 100644 c/LebedevRebusy/magnij_tantal_metally.c create mode 100644 c/ParallelsTest/1.c create mode 100644 c/ParallelsTest/10.c create mode 100644 c/ParallelsTest/4npipe.c create mode 100644 c/ParallelsTest/4unpipe.c create mode 100644 c/ParallelsTest/6.c create mode 100644 c/ParallelsTest/77.c create mode 100644 c/ParallelsTest/ParallelsTest/1.c create mode 100644 c/ParallelsTest/ParallelsTest/10.c create mode 100644 c/ParallelsTest/ParallelsTest/4npipe.c create mode 100644 c/ParallelsTest/ParallelsTest/4unpipe.c create mode 100644 c/ParallelsTest/ParallelsTest/Answers.txt create mode 100644 c/ParallelsTest/tmp.c create mode 100755 c/StShDinLibs/static/build.sh create mode 100644 c/StShDinLibs/static/demo_use.c create mode 100644 c/StShDinLibs/static/demo_use.o create mode 100644 c/StShDinLibs/static/libhello-static.a create mode 100644 c/StShDinLibs/static/libhello-static.o create mode 100644 c/StShDinLibs/static/libhello.c create mode 100644 c/StShDinLibs/static/libhello.h create mode 120000 c/ToUpperTest/build create mode 100755 c/ToUpperTest/build.sh create mode 100644 c/ToUpperTest/main.c create mode 100644 c/bigmalloc/bigmalloc.c create mode 100644 c/bigmalloc/bignew.cpp create mode 100644 c/getc/tmp2.c create mode 100644 c/glcube/molecule.c create mode 100644 c/stat/stattest.c create mode 100644 c/study/sigaction.c create mode 100644 cpp/21movSamokatAuto/main.cpp create mode 100644 cpp/akk/akk.cpp create mode 100644 cpp/bookAmmeraal/00/main.cpp create mode 100644 cpp/bookAmmeraal/01/main.cpp create mode 100644 cpp/bookAmmeraal/02/main.cpp create mode 100644 cpp/bookAmmeraal/03/main.cpp create mode 100644 cpp/bookAmmeraal/04/main.cpp create mode 100644 cpp/bookAmmeraal/05/main.cpp create mode 100644 cpp/bookAmmeraal/06/main.cpp create mode 100644 cpp/bookAmmeraal/07/main.cpp create mode 100755 cpp/bookAmmeraal/make_dirs.sh create mode 100644 cpp/gauss_miron/gauss.cpp create mode 100644 cpp/gauss_miron/gauss_mir.cpp create mode 100644 cpp/hello/hello.cpp create mode 100644 cpp/lu_solve/lu_solve.hpp create mode 100644 cpp/lu_solve/main.cpp create mode 100644 cpp/multithreading/asynch.c create mode 100644 cpp/multithreading/dish_ment.c create mode 100644 cpp/multithreading/event.c create mode 100644 cpp/multithreading/mutexes.c create mode 100644 cpp/multithreading/pthread_ex.c create mode 100644 cpp/multithreading/pthread_ex.cpp create mode 100644 cpp/multithreading/pthread_ex.geany create mode 100644 cpp/multithreading/pthread_ex.o create mode 100644 cpp/multithreading/sem08-1a.c create mode 100644 cpp/multithreading/sem08-1b.c create mode 100644 cpp/multithreading/semabinit.c create mode 100644 cpp/multithreading/time_test.c create mode 100644 cpp/multithreading/time_test.o create mode 100644 cpp/multithreading/tmp.c create mode 100644 cpp/multithreading/udp_socket.c create mode 100644 cpp/sockets/echo-client.c create mode 100644 cpp/sockets/echo-server.c create mode 100644 cpp/sockets/int2ip.c create mode 100644 cpp/sockets/ip2int.c create mode 100644 cpp/sockets/sock1.c create mode 100644 cpp/sockets/tmp1.c create mode 100644 cpp/wstring/wstring.cpp create mode 100755 gtk/hello_world/build.sh create mode 100755 gtk/hello_world/hello_world create mode 100644 gtk/hello_world/hello_world.c create mode 100644 java/helloworld1/.classpath create mode 100644 java/helloworld1/.project create mode 100644 java/helloworld1/hello.class create mode 100644 java/helloworld1/hello.java create mode 100644 nasm/div/2.asm create mode 100644 nasm/div/2.c create mode 100644 nasm/div/2.o create mode 100755 nasm/div/build create mode 100755 nasm/fact/1 create mode 100644 nasm/fact/1.asm create mode 100644 nasm/fact/1.c create mode 100644 nasm/fact/1.o create mode 100755 nasm/fact/build.sh create mode 100644 nasm/flags/build.sh create mode 100644 nasm/flags/flags create mode 100644 nasm/flags/flags.asm create mode 100644 nasm/flags/flags.c create mode 100644 nasm/flags/flags.o create mode 100644 nasm/lnxhello/build.sh create mode 100644 nasm/lnxhello/lnxhello.asm create mode 100644 nasm/lnxhello/lnxhello.o create mode 100644 perl/ping.pl create mode 100644 perl/study0.pl create mode 100644 php/ftrunc.php create mode 100644 php/strtotime create mode 100644 php/strtotime.php create mode 100644 prolog/parents.pl create mode 100644 prolog/parents2.pl create mode 100644 prolog/queens.pl create mode 100644 prolog/queens_fd.fd create mode 100644 python/akk.py create mode 100644 ruby/hello diff --git a/bash/delunpack/delunpack.sh b/bash/delunpack/delunpack.sh old mode 100644 new mode 100755 diff --git a/bash/delunpack/delunpack2.sh b/bash/delunpack/delunpack2.sh old mode 100644 new mode 100755 diff --git a/bash/delunpack/delunpack3.sh b/bash/delunpack/delunpack3.sh old mode 100644 new mode 100755 diff --git a/bash/delunpack/findunfiles.sh b/bash/delunpack/findunfiles.sh old mode 100644 new mode 100755 diff --git a/bash/delunpack/margin.sh b/bash/delunpack/margin.sh old mode 100644 new mode 100755 diff --git a/bash/delunpack/mkbaselist.sh b/bash/delunpack/mkbaselist.sh old mode 100644 new mode 100755 diff --git a/bash/delunpack/mkbaselist2.sh b/bash/delunpack/mkbaselist2.sh old mode 100644 new mode 100755 diff --git a/bash/gedit/geditmkrun.sh b/bash/gedit/geditmkrun.sh old mode 100644 new mode 100755 diff --git a/bash/gedit/geditxmkrun.sh b/bash/gedit/geditxmkrun.sh old mode 100644 new mode 100755 diff --git a/bash/gedit/hello.sh b/bash/gedit/hello.sh old mode 100644 new mode 100755 diff --git a/bash/gprs/3Gconnect.sh b/bash/gprs/3Gconnect.sh old mode 100644 new mode 100755 diff --git a/bash/gprs/3Gdisconnect.sh b/bash/gprs/3Gdisconnect.sh old mode 100644 new mode 100755 diff --git a/bash/gprs/3Gmake_bug.sh b/bash/gprs/3Gmake_bug.sh old mode 100644 new mode 100755 diff --git a/bash/gprs/3Greconnect.sh b/bash/gprs/3Greconnect.sh old mode 100644 new mode 100755 diff --git a/bash/ld_symlinks/tmp3.sh b/bash/ld_symlinks/tmp3.sh old mode 100644 new mode 100755 diff --git a/bash/studyBash/bash_script.sh b/bash/studyBash/bash_script.sh old mode 100644 new mode 100755 index efa534f..ba97449 --- a/bash/studyBash/bash_script.sh +++ b/bash/studyBash/bash_script.sh @@ -1,19 +1,19 @@ #!/bin/bash +echo $0 +#n=0 +#until [ $n -eq 4 ]; do +# echo $n +# let n=n+1 +#done -n=0 -until [ $n -eq 4 ]; do - echo $n - let n=n+1 -done - -n=0 -while [ ! $n -eq 4 ]; do - echo $n - let n=n+1 -done +#n=0 +#while [ ! $n -eq 4 ]; do +# echo $n +# let n=n+1 +#done # #Стирает все пустые файлы @@ -33,7 +33,7 @@ done #done -#for item in `cat amd64dirs` +#for item in `cat backbonedirs` #do # echo $item #done @@ -91,7 +91,7 @@ done #if (true) #[echo trigger.dat]; #then -#./mount_amd64.run +#./mount_backbone.run # echo "ON" # echo -n 0 > trigger.dat #fi @@ -99,7 +99,7 @@ done # echo "OFF" #fi #else -#./umount_amd64.run +#./umount_backbone.run # echo "OFF" # echo -n 1 > trigger.dat #elif diff --git a/bash/studyBash/read_file.sh b/bash/studyBash/read_file.sh new file mode 100755 index 0000000..526f2d1 --- /dev/null +++ b/bash/studyBash/read_file.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# Чтение строк из файла /etc/fstab. + +File=/etc/fstab + +{ +read line1 +read line2 +} < $File + +echo "Первая строка в $File :" +echo "$line1" +echo +echo "Вторая строка в $File :" +echo "$line2" + +exit 0 diff --git a/c/12309/test12309.c b/c/12309/test12309.c new file mode 100644 index 0000000..70c0aa7 --- /dev/null +++ b/c/12309/test12309.c @@ -0,0 +1,85 @@ +#include +#include +#include +#include +#include + +#define TIME_CYCLE_SEC 10 + +typedef unsigned long long ull; + +static ull max_wait_time = 0; + +void termination_handler (int signum) { + if(signum == SIGINT) { + printf("----------------------------\n"); + printf("Тест окончен!\n"); + printf ("Максимальная задержка за всё время = %llu микросекунд\n", max_wait_time); + exit(0); + } +} + +int max_wait_test() { + + signal(SIGINT, termination_handler); + + struct timezone tz; + tz.tz_minuteswest = 0; + tz.tz_dsttime = 0; + + struct timeval tv; + + gettimeofday(&tv, &tz); + ull last_time = ((ull)tv.tv_sec) * 1000000 + (ull)tv.tv_usec; + ull start_tv_sec = (ull)tv.tv_sec; + ull last_tv_sec = start_tv_sec; + ull average_wait_time = 0; + + while( 1 == 1 ) { + + gettimeofday(&tv, &tz); + + ull mcs = ((ull)tv.tv_sec) * 1000000 + (ull)tv.tv_usec; + + ull delta_time = mcs - last_time; + + if(delta_time > max_wait_time) + max_wait_time = delta_time; + + if(delta_time > average_wait_time) + average_wait_time = delta_time; + + + // noop на несколько наносекунд + struct timespec wait_ts; + wait_ts.tv_sec = 0; + wait_ts.tv_nsec = 10; + nanosleep(&wait_ts,NULL); + + // Выводим каждые TIME_CYCLE_SEC секунд среднюю задержку за эти TIME_CYCLE_SEC секунд + if(last_tv_sec + TIME_CYCLE_SEC <= tv.tv_sec) { + printf("----------------------------\n"); + printf("Время выполнения = %llu секунд\n", last_tv_sec - start_tv_sec); + printf("Максимальная задержка за %d секунд = %llu микросекунд\n", TIME_CYCLE_SEC, average_wait_time); + printf ("Максимальная задержка за всё время = %llu микросекунд\n", max_wait_time); + fflush(stdout); + gettimeofday(&tv, &tz); + last_tv_sec = tv.tv_sec; + mcs = ((ull)tv.tv_sec) * 1000000 + (ull)tv.tv_usec; + average_wait_time = 0; + } + + // сохраняем последнюю отметку времени + last_time = mcs; + } + + return EXIT_SUCCESS; +} + +int main(int argc, char * argv[]) { + + max_wait_test(); + + return EXIT_SUCCESS; +} + diff --git a/c/5minLorTest/5min.c b/c/5minLorTest/5min.c new file mode 100644 index 0000000..26d1bf3 --- /dev/null +++ b/c/5minLorTest/5min.c @@ -0,0 +1,19 @@ +#include +#include + +int main(int argc, char * argv[]) +{ + int i = 0; + + for (i = 0; i < 100; i++) + if (i%3 == 0 && i%5 == 0) + printf("FizzBuzz\n"); + else if (i%3 == 0) + printf("Fizz\n"); + else if (i%5 == 0) + printf("Buzz\n"); + else + printf("%d\n", i); + + return EXIT_SUCCESS; +} diff --git a/c/5minLorTest/typical_errors_in_c.c b/c/5minLorTest/typical_errors_in_c.c new file mode 100644 index 0000000..8ab7d90 --- /dev/null +++ b/c/5minLorTest/typical_errors_in_c.c @@ -0,0 +1,12 @@ +#include +#include + +#define MALLOC(x,y) { y=malloc(x); if (!y) abort(); } + +int main(int argc, char * argv[]) +{ + void * p = NULL; + MALLOC(3,p); + + return EXIT_SUCCESS; +} diff --git a/c/LebedevRebusy/koka_kola_voda.c b/c/LebedevRebusy/koka_kola_voda.c new file mode 100644 index 0000000..c6d8d3b --- /dev/null +++ b/c/LebedevRebusy/koka_kola_voda.c @@ -0,0 +1,39 @@ +#include +#include + +int main(int argc, char * argv[]) { + + int k, o, a, l, v, d; + int left1, left2, right; + + for(k=0; k<10; k++) + for(o=0; o<10; o++) + for(a=0; a<10; a++) + for(l=0; l<10; l++) + for(v=0; v<10; v++) + for(d=0; d<10; d++) { + left1=left2=right=0; + left1 *= 10; left1 += k; + left1 *= 10; left1 += o; + left1 *= 10; left1 += k; + left1 *= 10; left1 += a; + left2 *= 10; left2 += k; + left2 *= 10; left2 += o; + left2 *= 10; left2 += l; + left2 *= 10; left2 += a; + right*=10; right+=v; + right*=10; right+=o; + right*=10; right+=d; + right*=10; right+=a; + if(k==o || k==a || k==l || k==v || k==d || + o==a || o==l || o==v || o==d || a==l || a==v || + a==d || l==v || l==d || v==d) + continue; + if(left1 + left2 == right) { + printf("%d%d%d%d+%d%d%d%d=%d%d%d%d\n",k,o,k,a,k,o,l,a,v,o,d,a); + } + } + + + return 0; +} diff --git a/c/LebedevRebusy/koza_koza_stado.c b/c/LebedevRebusy/koza_koza_stado.c new file mode 100644 index 0000000..e2b61a0 --- /dev/null +++ b/c/LebedevRebusy/koza_koza_stado.c @@ -0,0 +1,52 @@ +#include +#include + +int main(int argc, char * argv[]) { + + //~ const char * eq = "КОЗА+КОЗА=СТАДО"; + //~ int len = strlen(eq); + //~ int i = 0; + //~ char A='А'; + //~ for(i=0; i +#include +#include +#include +/* Reading some text from the pipe. */ +void +read_from_pipe (int file) +{ + FILE *stream; + int c; + stream = fdopen (file, "r"); + while ( (c=fgetc(stream)) != EOF) + putchar(c); +//while(1==1) printf("%d\n",fgetc(stream)); + fclose (stream); +} +/* Writing some text to the pipe. */ +void +write_to_pipe (int file) +{ + FILE *stream; + stream = fdopen (file, "w"); + fprintf (stream, "hello, world!\n"); + fprintf (stream, "goodbye, world!\n"); + fclose (stream); +} +int +main (void) +{ + pid_t pid; + int mypipe[2]; + /* Creating unnamed pipe. */ + if (pipe (mypipe)) + { + fprintf(stderr, "Pipe failed.\n"); + return EXIT_FAILURE; + } + /* Creating child process because we need 2 processes to work with the pipe. */ + pid = fork (); + if (pid == (pid_t) 0) + { + /* Child process opens the pipe for reading. */ + printf("child process for reading started\n"); + read_from_pipe (mypipe[0]); +// write_to_pipe (mypipe[1]); + close(mypipe[1]); + printf("child process ended\n"); + return EXIT_SUCCESS; + } + else if (pid < (pid_t) 0) + { + /* If fork() failed. */ + fprintf(stderr,"Fork failed.\n"); + return EXIT_FAILURE; + } + else + { + /* Main (parent) process writes some data to the pipe. */ + printf("parent process for writing started\n"); + write_to_pipe (mypipe[1]); +// read_from_pipe (mypipe[0]); + printf("parent process ended\n"); + return EXIT_SUCCESS; + } +} diff --git a/c/ParallelsTest/6.c b/c/ParallelsTest/6.c new file mode 100644 index 0000000..a3c4ae2 --- /dev/null +++ b/c/ParallelsTest/6.c @@ -0,0 +1,10 @@ +#include +#include + +int main(int argc, char * argv[]) { + int i; + for(i=0; i<10; i++) { + fork(); + printf("Hello, world!\n"); + } +} diff --git a/c/ParallelsTest/77.c b/c/ParallelsTest/77.c new file mode 100644 index 0000000..3a57803 --- /dev/null +++ b/c/ParallelsTest/77.c @@ -0,0 +1,48 @@ +#include +#include +char string[] = "hello world"; +main() +{ +int count,i; +int to_par[2],to_chil[2]; /* + */ +char buf[256]; +pipe(to_par); +pipe(to_chil); +if (fork() == 0) +{ + /* */ + close(0); /* */ + dup(to_chil[0]); /* + + */ + close(1); /* */ + dup(to_par[0]); /* + + */ + close(to_par[1]); /* + close(to_chil[0]); */ + close(to_par[0]); + close(to_chil[1]); + for (;;) + { + if ((count = read(0,buf,sizeof(buf))) == 0) + exit(0); + write(1,buf,count); + } +} +/* */ +close(1); /* - */ +dup(to_chil[1]); +close(0); +dup(to_par[0]); +close(to_chil[1]); +close(to_par[0]); +close(to_chil[0]); +close(to_par[1]); +for (i = 0; i < 15; i++) +{ + write(1,string,strlen(string)); + read(0,buf,sizeof(buf)); +} +} diff --git a/c/ParallelsTest/ParallelsTest/1.c b/c/ParallelsTest/ParallelsTest/1.c new file mode 100644 index 0000000..57796ab --- /dev/null +++ b/c/ParallelsTest/ParallelsTest/1.c @@ -0,0 +1,18 @@ +#include +#include +#include + +void +termination_handler (int signum) { + printf ("Performing kill task...\n"); + exit(0); +} + +int main(int argc, char * argv[]) { + + signal(SIGINT, termination_handler); + + while(1==1); + + return 0; +} diff --git a/c/ParallelsTest/ParallelsTest/10.c b/c/ParallelsTest/ParallelsTest/10.c new file mode 100644 index 0000000..caa9825 --- /dev/null +++ b/c/ParallelsTest/ParallelsTest/10.c @@ -0,0 +1,34 @@ +#include +#include +#include +#include +#include + +#ifndef INITIAL_LIMIT +# define INITIAL_LIMIT 1025 +#endif +char buf[2*INITIAL_LIMIT]; + +write_to_file(int id) { + + char link[64]; + char * links = "/proc/self/fd/"; + sprintf(link, "%s", links); + sprintf(link+strlen(links), "%d", id); + //printf("link=%s\n", link); + readlink(link, buf, INITIAL_LIMIT); + //printf("buf=%s\n", buf); + close(id); + id = open(buf, O_WRONLY); + write(id, "Hello world!\n", 13); + close(id); +} + +int main(int argc, char * argv[]) { + + int id = open("tmp.txt", O_RDONLY); + + write_to_file(id); + + return (0); +} diff --git a/c/ParallelsTest/ParallelsTest/4npipe.c b/c/ParallelsTest/ParallelsTest/4npipe.c new file mode 100644 index 0000000..584875b --- /dev/null +++ b/c/ParallelsTest/ParallelsTest/4npipe.c @@ -0,0 +1,67 @@ +#include +#include +#include +#include +#include +#include +#include + +void syserr( const char *msg ) { + perror(msg); + exit(EXIT_FAILURE); +} + +main() +{ + int rfd, wfd; + char buff[64096]; + int nb; + int ed; + + remove("duck"); + + if( mkfifo( "duck", 0666 ) == -1 ) { + syserr( "mkfifo" ); + } + + switch( fork() ) { + case -1: syserr("fork" ); break; + case 0: // child + printf( "Child awakes\n" ); + if( (rfd = open( "duck", O_RDWR )) == -1 ) { + syserr( "open for reading" ); + } + printf("Child: open completes\n"); + + for( ; ; ) { + if( (nb = read( rfd, buff, 200 )) == -1 ) { + syserr( "read" ); + } + if( nb == 0 ) { + printf("No more data\n"); + printf("child terminates 0\n"); + exit( 0 ); + } + buff[nb] = '\0'; + printf("nb = %d Buff = |%s|\n", nb, buff); + } + break; + default: // parent + printf( "Parent awake\n" ); + if( (wfd = open( "duck", O_RDWR )) == -1 ) { + syserr( "open for writing" ); + } + printf("Parent opened pipe to write\n"); + + for( ed = 0; ed < 4; ed++ ) { + sprintf( buff, "duckie %d", ed + 1 ); + if(write( wfd, buff, strlen(buff)) != strlen(buff)) { + syserr( "write" ); + } + } + printf("parent terminates\n"); + close(wfd); + remove("duck"); + sleep(1); + } +} diff --git a/c/ParallelsTest/ParallelsTest/4unpipe.c b/c/ParallelsTest/ParallelsTest/4unpipe.c new file mode 100644 index 0000000..83b0893 --- /dev/null +++ b/c/ParallelsTest/ParallelsTest/4unpipe.c @@ -0,0 +1,65 @@ +#include +#include +#include +#include +/* Reading some text from the pipe. */ +void +read_from_pipe (int file) +{ + FILE *stream; + int c; + stream = fdopen (file, "r"); + while ( (c=fgetc(stream)) != EOF) + putchar(c); +//while(1==1) printf("%d\n",fgetc(stream)); + fclose (stream); +} +/* Writing some text to the pipe. */ +void +write_to_pipe (int file) +{ + FILE *stream; + stream = fdopen (file, "w"); + fprintf (stream, "hello, world!\n"); + fprintf (stream, "goodbye, world!\n"); + fclose (stream); +} +int +main (void) +{ + pid_t pid; + int mypipe[2]; + /* Creating unnamed pipe. */ + if (pipe (mypipe)) + { + fprintf(stderr, "Pipe failed.\n"); + return EXIT_FAILURE; + } + /* Creating child process because we need 2 processes to work with the pipe. */ + pid = fork (); + if (pid == (pid_t) 0) + { + /* Child process opens the pipe for reading. */ + printf("child process for reading started\n"); + read_from_pipe (mypipe[0]); +// write_to_pipe (mypipe[1]); + close(mypipe[1]); + printf("child process ended\n"); + return EXIT_SUCCESS; + } + else if (pid < (pid_t) 0) + { + /* If fork() failed. */ + fprintf(stderr,"Fork failed.\n"); + return EXIT_FAILURE; + } + else + { + /* Main (parent) process writes some data to the pipe. */ + printf("parent process for writing started\n"); + write_to_pipe (mypipe[1]); +// read_from_pipe (mypipe[0]); + printf("parent process ended\n"); + return EXIT_SUCCESS; + } +} diff --git a/c/ParallelsTest/ParallelsTest/Answers.txt b/c/ParallelsTest/ParallelsTest/Answers.txt new file mode 100644 index 0000000..322d5be --- /dev/null +++ b/c/ParallelsTest/ParallelsTest/Answers.txt @@ -0,0 +1,62 @@ +1. +(a) SIGINT signal sends to the main process +(b) Example of SIGINT signal handler in the attachment: 1.c + +2. Signals, shared memory, semaphors, mutexes, critical sections, events, named(streams) and unnamed pipes, sockets, local variables. + +3. some_file will contain data(standard input stream) transfered through the unnamed pipe by simbol '|' to the 'echo' command. + In that specific case some_file will contain no data. + +4. Unnamed pipe is a set of processes chained by their standard streams. + Named pipe is a method of inter-process communication which has name in the file system tree. + +In shell: + +$ mkfifo my_pipe +or +$ mknod my_pipe p +will create a fifo pipe +For example we can use it for compress some data. +First process: +$ gzip -9 -c < my_pipe > out.gz +Second: +$ cat Tsoj.txt > my_pipe +and removing pipe: +$ rm my_pipe +or we can use '|' charecter for unnamed pipes (tubes/conveyors). + +In C: + +Function pipe(int id[2]) declared in unistd.h will create unnamed pipe, + example of using it: 4unpipe.c is in the attachment. + Function mkfifo (const char *filename, mode_t mode) declared in 'sys/stat.h' + may create named pipe. Example: 4npipe.c is in the attachment. + +If the receiving end of a pipe dies while the sending end still wants to write to the pipe +sending end will die too ! + +5. (a) TCP server: socket, bind, listen, accept; + (b) TCP client: socket, connect. + +6. The program prints "Hello world!\n" of maximum child process number in UNIX times. + 10240 times on my Linux system. And then the program exits with bad status. + +7. In run time we can use 'lsof' or 'fuser' command to find out is it opening any file or not. + 'ldd' use to find out which libraries it uses when not running executable file. + finally $hex some.out|less, then press '/', input file name and search for the binary code. + +8. Something like this: + telnet mail.server.ua 25 + helo 95.83.108.87 + mail from: mecareful@server.ua + rcpt to: somebody@somewhere.com + Subject: Test letter + Please don't reply to this letter. + quit + +9. Hard link is a directory reference, or pointer, to a file on a storage volume. + $ ln some_file hard_link + creates a hard link hard_link with the same node as a some_file. +Example 9.sh in the attachment shows which three files are hardlinked to each other. + +10. I use /proc/self/fd, example in the attachment: 10.c. diff --git a/c/ParallelsTest/tmp.c b/c/ParallelsTest/tmp.c new file mode 100644 index 0000000..da96d53 --- /dev/null +++ b/c/ParallelsTest/tmp.c @@ -0,0 +1,10 @@ +#include + +int main(int argc, char * argv[]) { + FILE * stream; + int c; + stream = fopen("myfifo","r"); + while ((c=fgetc(stream)) != EOF) + printf("%d\n",c); + return (0); +} diff --git a/c/StShDinLibs/static/build.sh b/c/StShDinLibs/static/build.sh new file mode 100755 index 0000000..b0debbb --- /dev/null +++ b/c/StShDinLibs/static/build.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +#Создаем объектный файл +gcc -Wall -g -c -o libhello-static.o libhello.c && \ +#Создаем статическую библиотеку +ar rcs libhello-static.a libhello-static.o && \ +#Если обладаете правами суперпользователя, то можно выполнить +#cp libhello-static.a /usr/local/lib/ +#Иначе оставляем статическую библиотеку в текущей директории +#Создаем объектный файл +gcc -Wall -g -c demo_use.c -o demo_use.o && \ +#Создаем исполняемый файл +#-L. - этот параметр указывает компилятору, что библиотеку следует искать в текущей директории. +#-lhello-static - этот параметр указывает компилятору, что библиотека помещается в файле +#libhello-static.расширение (.a, .o, .so). +gcc -g -o demo_use_static demo_use.o -L. -lhello-static && \ +#Выполнение исполняемого файла +./demo_use_static diff --git a/c/StShDinLibs/static/demo_use.c b/c/StShDinLibs/static/demo_use.c new file mode 100644 index 0000000..37f5c48 --- /dev/null +++ b/c/StShDinLibs/static/demo_use.c @@ -0,0 +1,6 @@ +#include "libhello.h" + +int main() { + hello(); + return 0; +} diff --git a/c/StShDinLibs/static/demo_use.o b/c/StShDinLibs/static/demo_use.o new file mode 100644 index 0000000000000000000000000000000000000000..1f8b3be4c07361fd5c4f108e38b9b1d8eb4f434d GIT binary patch literal 3104 zcmbVOJ8u&~5Z?185O89g5FjWNMgjy9IfF<6M9M>k1VliAC`GF1>|C(Hz6*hvtgU*nX-=$Q>Q&atJ?qYT# zdv!m+X#(A2Dx00mx_y*&lb#IHRbN7##-F$`WORsoy^VAlZclG5jFp-|tU5}g~D#zF?t$)Elk{}+b%R>Te@nnYwpHUp;Q?6#=UdqE{fHt5ftx6bw4aFG^0B~C2kc< z#l?8BdZ`x9*UGJ8EB51Bg_-9{rHh4=b3qtKk*-!)KkJ=2#g&O{mRPdXAcpI25Nb68uC2BNi z-^vT4IPj>SW7L_-UCs-tD{D=vBfHtLE>I@UPP;E$X_~eDg5?~sTaA)oWAHuOt0P9V zQU^$bM~;u+Cm1)bZIZE&jNOCHg@cKjJIy~!xpH?*HsK#P!IaobDHu|oVj#gyGR5Ya zBB#A4#J}eL$z?|W@Q&>Mp}t*{AoU#s3F@0-$6}vp{BN>4OWqUs!EN*VgxNKbIl|yP zCWhFt_sC~s2w!Co=gSm3wocBp^?yoPKOlSkTZGv)!MDla8B7eZW1o;OjsF|-OFsHH zK#$G;k}%YiI5HD?$3(LNuoiyNuL)1f|IGmf&J!hhqTh19_(dORe`*BLTJi+_NCq%F ze1w7X63ANiFYpI4()!oeuOrO!H$;%+3qDAgefN>M!2Dk@F~nYf+S(ERjfq}y!a>6J z(PQ)PAuNr5o$oKcsixTcrq8qy*Q0*@GcmE<)Dw$!q^$&aT8Dx6O34oGc6|-B+imZ@ zBb@5+W;_VF6Za4hP&?CQ45#7oMIex zcC!stWLxUb@caU6oICR_i(hc5f7PfXcLI>dxWx0ceWJiCy@F3{8y6nCP60_ISfjbl E|MSqT-2eap literal 0 HcmV?d00001 diff --git a/c/StShDinLibs/static/libhello-static.a b/c/StShDinLibs/static/libhello-static.a new file mode 100644 index 0000000000000000000000000000000000000000..ccf24dd0918495a834e55d514e8cf15cbe0b37a9 GIT binary patch literal 3838 zcmbtXO>7%g5T4z2h-)X7lTv;Z4jYM5ipttfEmH-Q2Dv3cM5rRlfm5?~wy}w`8`hgP z;Q}W_4e5~{?h5|?sE0)#+t-^n`l1&N1_{*cRO0wAd`Txp>vn0- z@2Dg%4zn=pcY~x>D%D1Ioxtp@QLm#F*Cn;Kn%LFF7WGWDU3&lO#%r!a&1rIAMYSrr z@DooYfK?@~!c%Ytw$^X|@eS!GwEXPMXbP9#Hu1!N7zjf83DWz)F08ucqMr0gGR^& zym*kLj%XqYTa5i2#>4(@9PRitvOyB>`eO(iyS*@lVJ}HD%d8*@)y<4zRe(xI##%4g zk7|3#AdG9*(&U|}n+~ zb2sd6s1j9A8PA+yW zdJHJ%e~oWoEY-J3>aSY{+xH6EZHz+ha2!3jCfUB1(P;09{2%cAe&PU{AKfE+ep`sy zIT3=h46cx3knKzR%&UKIRtL#_qWV}rh~iAL>-W)UW8{C#;D#BT z<9nQgQOFM*FYf}vi0oP!VtM=jHfR4c=xgu)lboCg!S7s1&Oc#9c76Ii%&Y$^*Oz#j zBmU4%)c>4wiXW?jB-`;{bG*-S!X!@kS7;Dfe2D*M9|$(uzCR*P znC&+@<2y`$KOG!qL;PB1Cz^zu5rSkg^f*xUzaMIn-)pi literal 0 HcmV?d00001 diff --git a/c/StShDinLibs/static/libhello-static.o b/c/StShDinLibs/static/libhello-static.o new file mode 100644 index 0000000000000000000000000000000000000000..80cd2a55185e0ded266bedeb5b7a0263bbac61b0 GIT binary patch literal 3616 zcmbtXO>7%g5T5lq#Kno_q?8|p!&aiuqOwj!1t>^qkXsT&gesyOI8|$BYnwQ`VZCV+ zE^tEh0OD97p}R7To;GvCZN^WN-x>-9%h zHs7px9;tY=N)IhXiH`k;`kGPK=xI7d+Z(t3`VRInZomHMEqG@dC+mJ=sj=WKddo3fKv&I~{#a9I>sb;2AHYel8tx}scgU5N< zsuWgLK%`@E27_On86-Iqj8(18Ry^aLDT-9f%d8*)o#wme{nMD|yXhDQdo&z$`tfj> zhF#<*I#JA;wNr23sZ=<21Mc$y2WC-r6x>X+;ZA5`anp(wx>>B0v8s3(YpUKHV>eV4 zg!n;Vevr@jO8GKV0zl{al13U^Z&OLcVXfyN84Y?#yc3{h!!+py6Nosw{V1bRKh1K- zZ6HvK$&9&%VA8?a>Zf~gYd0N6N$YBsz8`nrMcPK7u@q_8OH@N zt$3r+Y=2UjH@g8~I6B(PqYjUGR*ZesvUnJUd3=~txD(|Og`Lre)wpxeyB2jiS$u;+ z6H`EggI1g6zza(Hbw(7V)l5I^!cRT5}6*n!h;$raKs}~W=#XwK;h&tvZ z^N6htd7dxe)@ukbT{ZXVn_COV068C(e}TEE?~2yna2#&zW%j!mD7S@&gKLW$dx@Ry znh<|q`uB?v&_6sQw}0D=xj7l4GXk!{u*8kUI?L+coi9lGoKPRN-TDz@$T@yHvJUA= zA@FQ*>kruJVu(KyaMLE2#2%Gkp!_6!eHQ?OxV3V|%GUpV$@=Fw)?NSSB{>i;hFm5)C15A9U_uOz3&v1w#M9>~`U$f)&oyvsOrm;bHs1L5hQJRQGb zhw2)G@eg-Hh|`VznQ>rl_gUFzbDyNzTyjvx$h3c6Yw_} zmbmjTn>)gfPZXqkLU@YJCSPuSgq795E$1IRTip7#&(;xFrN1B8nCgD%6T>{pW&*sd z!@$kgmZlw#{?xBY;qu3;ABP&nr^hD&v3!yyI9{J{5~syCC!`EV=cmP|#c7ZcpRiM= z#V72RNx@7Ot$u1HWLABGVSR@c-%tAo`G~)kB?z6+JpxEOgX4he|2`;0f3M+JF013t z0LR?!0A$gbD_)@dF)NDV`(i&Mqr1OPJGid#oR!CXpNqY0;h2w}yH_3jJ+bxoO6T*6 z;8&b@-5Hw>{-W4h4*r(dk%RZd-gWRV#s0v-HSeL|Zht;@aP7~hRvvjZ7)1XtxOwd7 Yt2zj(qd%$x*E(*V08SR{ANw8qA5lc>(f|Me literal 0 HcmV?d00001 diff --git a/c/StShDinLibs/static/libhello.c b/c/StShDinLibs/static/libhello.c new file mode 100644 index 0000000..475da9e --- /dev/null +++ b/c/StShDinLibs/static/libhello.c @@ -0,0 +1,6 @@ +#include +#include "libhello.h" + +void hello(void) { + printf("Hello, library world.\n"); +} diff --git a/c/StShDinLibs/static/libhello.h b/c/StShDinLibs/static/libhello.h new file mode 100644 index 0000000..ef77476 --- /dev/null +++ b/c/StShDinLibs/static/libhello.h @@ -0,0 +1 @@ +void hello(void); diff --git a/c/ToUpperTest/build b/c/ToUpperTest/build new file mode 120000 index 0000000..c07a74d --- /dev/null +++ b/c/ToUpperTest/build @@ -0,0 +1 @@ +build.sh \ No newline at end of file diff --git a/c/ToUpperTest/build.sh b/c/ToUpperTest/build.sh new file mode 100755 index 0000000..13bb4bd --- /dev/null +++ b/c/ToUpperTest/build.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +rm -f test test.o +gcc -static -o test main.c +#gcc -c -static test.o main.c && \ +#ld -static -o test test.o && \ +#rm test.o + +./test diff --git a/c/ToUpperTest/main.c b/c/ToUpperTest/main.c new file mode 100644 index 0000000..53e94e6 --- /dev/null +++ b/c/ToUpperTest/main.c @@ -0,0 +1,23 @@ +#include +#include +#include +#include + +#define MaxLen 1024 +char STR1[1024], STR2[1024]; +int strcomp(const char * str1, const char * str2) +{ + char * p1 = STR1, * p2 = STR2; + while(*p1++=toupper(*str1++)); + while(*p2++=toupper(*str2++)); + return strcmp(STR1,STR2); + return 0; +} + +int main(int argc, char * argv[]) +{ + printf("%d\n", strcomp("Hello\0","heLLo\0")); + printf("%d\n", strcomp("aello\0","BeLLo\0")); + printf("%d\n", strcomp("bello\0","AeLLo\0")); + return 0; +} diff --git a/c/bigmalloc/bigmalloc.c b/c/bigmalloc/bigmalloc.c new file mode 100644 index 0000000..f547be5 --- /dev/null +++ b/c/bigmalloc/bigmalloc.c @@ -0,0 +1,20 @@ +#include +#include +#include + +int main(int argc, char *argv[]) +{ + int sz = 1524*1024*1024; + printf("%d",sz); + char * m = (char*)malloc(sz); + if(m==NULL) + { + printf("malloc failed\n"); + exit(-1); + } + int i; + for(i=0; i +#include +#include + +using namespace std; + +int main(int argc, char *argv[]) +{ + int sz = 1024*1024*1024; + cout< +#include + +int main(int argc, char * argv[]) +{ + printf("Hello, world!\n"); + getc(stdin); + return EXIT_SUCCESS; +} diff --git a/c/glcube/molecule.c b/c/glcube/molecule.c new file mode 100644 index 0000000..a50b63c --- /dev/null +++ b/c/glcube/molecule.c @@ -0,0 +1,152 @@ +#include + + +/* подключаем библиотеку GLUT */ + +#include + + + +/* начальная ширина и высота окна */ + +GLint Width = 512, Height = 512; + + + +/* размер куба */ + +const int CubeSize = 200; + + + +/* эта функция управляет всем выводом на экран */ + +void Display(void) + +{ + + int left, right, top, bottom; + + + + left = (Width - CubeSize) / 2; + + right = left + CubeSize; + + bottom = (Height - CubeSize) / 2; + + top = bottom + CubeSize; + + + + glClearColor(0, 0, 0, 1); + + glClear(GL_COLOR_BUFFER_BIT); + + + + glColor3ub(255,0,0); + + glBegin(GL_QUADS); + + glVertex2f(left,bottom); + + glVertex2f(left,top); + + glVertex2f(right,top); + + glVertex2f(right,bottom); + + glEnd(); + + + + glFinish(); + +} + +/* Функция вызывается при изменении размеров окна */ + +void Reshape(GLint w, GLint h) + +{ + + Width = w; + + Height = h; + + + + /* устанавливаем размеры области отображения */ + + glViewport(0, 0, w, h); + + + + /* ортографическая проекция */ + + glMatrixMode(GL_PROJECTION); + + glLoadIdentity(); + + glOrtho(0, w, 0, h, -1.0, 1.0); + + + + glMatrixMode(GL_MODELVIEW); + + glLoadIdentity(); + +} + + + + + +/* Функция обрабатывает сообщения от клавиатуры */ + +void + +Keyboard( unsigned char key, int x, int y ) + +{ + +#define ESCAPE '\033' + + + + if( key == ESCAPE ) + + exit(0); + +} + + + +/* Главный цикл приложения */ + +main(int argc, char *argv[]) + +{ + + glutInit(&argc, argv); + + glutInitDisplayMode(GLUT_RGB); + + glutInitWindowSize(Width, Height); + + glutCreateWindow("Red square example"); + + + + glutDisplayFunc(Display); + + glutReshapeFunc(Reshape); + + glutKeyboardFunc(Keyboard); + + + + glutMainLoop(); + +} diff --git a/c/stat/stattest.c b/c/stat/stattest.c new file mode 100644 index 0000000..71f895e --- /dev/null +++ b/c/stat/stattest.c @@ -0,0 +1,12 @@ +#include +#include +#include +#include + +int main(int argc, char * argv[]) +{ + + printf("%ld", sizeof(off_t)); + + return 0; +} diff --git a/c/study/sigaction.c b/c/study/sigaction.c new file mode 100644 index 0000000..12d3b11 --- /dev/null +++ b/c/study/sigaction.c @@ -0,0 +1,20 @@ +#include +#include +#include +void term_handler(int i) +{ printf ("Terminating\n"); +exit(EXIT_SUCCESS); +} +int main(int argc, char ** argv) { +struct sigaction sa; +sigset_t newset; +sigemptyset(&newset); +sigaddset(&newset, SIGHUP); +sigprocmask(SIG_BLOCK, &newset, 0); +sa.sa_handler = term_handler; +sigaction(SIGTERM, &sa, 0); +printf("My pid is %i\n", getpid()); +printf("Waiting...\n"); +while(1) sleep(1); +return EXIT_FAILURE; +} diff --git a/cpp/21movSamokatAuto/main.cpp b/cpp/21movSamokatAuto/main.cpp new file mode 100644 index 0000000..b8db882 --- /dev/null +++ b/cpp/21movSamokatAuto/main.cpp @@ -0,0 +1,31 @@ +#include +#include +#include + +using namespace std; + +const int NEXPER = 10000; + +int main(void) { + srand(time(0)); + + int M = 0, N = 0; + // Повторяем эксперимент NEXPER раз + for (N = 0; N < NEXPER; N++) { + // за одной из 3-х досок автомобиль + int WonDesk = rand()%3 + 1; // 1,2 или 3 + // мы указываем на доску №1, + // после чего ведущий открывает 1-ну из досок + int OdnaIsDosok = rand()%2 + 2; // 2 или 3 + if (OdnaIsDosok == WonDesk) { // если за ней автомобиль, то он должен однозначно открыть не эту + OdnaIsDosok = OdnaIsDosok==2 ? 3 : 2; + } + // мы изменяем выбор и подсчитываем вероятность + if (WonDesk != 1) M++; // если автомобиль не за 1-ой доской, то при изменении выбора едем домой на 4-х =) + } + + cout << "p = " << (double(M)/double(N)) << endl; + + return 0; +} + diff --git a/cpp/akk/akk.cpp b/cpp/akk/akk.cpp new file mode 100644 index 0000000..f5271a1 --- /dev/null +++ b/cpp/akk/akk.cpp @@ -0,0 +1,14 @@ +#include +#include +using namespace std;ывав +typedef unsigned long long ll; +ll f(ll m, ll n) { + if(m==0) return n+1; + if(n==0) return f(m-1,1); + return f(m-1,f(m,n-1)); +} +int main(int argc, char *argv[]) +{ + for(int i=0;i<30;i++) cout << "akk("<<3<<";"< +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +/* STD */ +#include +#include +#include +#include +using namespace std; + +void showlist (const char *str, const list &L) { + list::const_iterator i; + cout << str << endl << " "; + for (i=L.begin(); i != L.end(); ++i) + cout << *i << " "; + cout << endl; +} + +int main (int argc, char *argv[]) { + list L; + int x; + cout << "Enter positive integers, followed by 0:\n"; + while (cin >> x, x != 0) + L.push_back(x); + showlist("Initial list:", L); + L.push_front(123); + showlist("After inserting 123 at the beginning:", L); + list::iterator i = L.begin(); + L.insert(++i, 456); + showlist("After inserting 456 at the second position:", L); + i = L.end(); + L.insert(--i, 999); + showlist("After inserting 999 just before the end:", L); + i = L.begin(); x = *i; + L.pop_front(); + cout << "Deleted at the beginning: " << x << endl; + showlist("After this deletion:", L); + i = L.end(); x = *--i; + L.pop_back(); + cout << "Deleted at the end: " << x << endl; + showlist("After this deletion:", L); + i = L.begin(); + x = *++i; cout << "To be deleted: " << x << endl; + L.erase(i); + showlist("After this deletion (of second element):", L); + return 0; +} + diff --git a/cpp/bookAmmeraal/01/main.cpp b/cpp/bookAmmeraal/01/main.cpp new file mode 100644 index 0000000..6cb2e46 --- /dev/null +++ b/cpp/bookAmmeraal/01/main.cpp @@ -0,0 +1,34 @@ +/* STL */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +/* STD */ +#include +#include +#include +#include +using namespace std; + +int main (int argc, char *argv[]) { + vector v; + int x; + cout << "Enter positive integers, followed by 0:\n"; + while (cin >> x, x !=0) v.push_back(x); + sort(v.begin(), v.end()); + cout << "After sorting: \n"; + vector::iterator i; + for (i=v.begin(); i != v.end(); ++i) + cout << *i << " "; + cout << endl; + return 0; +} diff --git a/cpp/bookAmmeraal/02/main.cpp b/cpp/bookAmmeraal/02/main.cpp new file mode 100644 index 0000000..3e63e33 --- /dev/null +++ b/cpp/bookAmmeraal/02/main.cpp @@ -0,0 +1,33 @@ +/* STL */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +/* STD */ +#include +#include +#include +#include +using namespace std; + +int main (int argc, char *argv[]) { + int a[10], x, n = 0, *p; + cout << "Enter at most 10 positive integers, followed by 0:\n"; + while (cin >> x, x != 0 && n < 10) a[n++] = x; + sort(a, a+n); + cout << "After sorting: \n"; + for (p=a; p != a+n; p++) cout << *p << " "; + cout << endl; + + + return 0; +} diff --git a/cpp/bookAmmeraal/03/main.cpp b/cpp/bookAmmeraal/03/main.cpp new file mode 100644 index 0000000..2e88618 --- /dev/null +++ b/cpp/bookAmmeraal/03/main.cpp @@ -0,0 +1,42 @@ +/* STL */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +/* STD */ +#include +#include +#include +#include +using namespace std; + +// 1.5. Алгоритм find Найти заданное значение в векторе + +int main (int argc, char *argv[]) { + vector v; + int x; + cout << "Enter positive integers, followed by 0:\n"; + while (cin >> x, x != 0) + v.push_back(x); + + cout << "Value to be searched for: "; + cin >> x; + vector::iterator i = find(v.begin(), v.end(), x); + if (i == v.end()) cout << "Not found\n"; + else { + cout << "Found"; + if (i == v.begin()) cout << " as the first element"; + else cout << " after " << *--i; + } + cout << endl; + return 0; +} diff --git a/cpp/bookAmmeraal/04/main.cpp b/cpp/bookAmmeraal/04/main.cpp new file mode 100644 index 0000000..0a77ca1 --- /dev/null +++ b/cpp/bookAmmeraal/04/main.cpp @@ -0,0 +1,32 @@ +/* STL */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +/* STD */ +#include +#include +#include +#include +using namespace std; + +int main (int argc, char *argv[]) { + int a[4] = {10, 20, 30, 40}; + vector v(a, a+4); + list L(4); // Список из 4 элементов + copy(v.begin(), v.end(), inserter(L, L.begin()));//L.begin()); + list::iterator i; + for (i=L.begin(); i != L.end(); ++i) + cout << *i << " "; + cout << endl; + return 0; +} diff --git a/cpp/bookAmmeraal/05/main.cpp b/cpp/bookAmmeraal/05/main.cpp new file mode 100644 index 0000000..eff2b0a --- /dev/null +++ b/cpp/bookAmmeraal/05/main.cpp @@ -0,0 +1,32 @@ +/* STL */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +/* STD */ +#include +#include +#include +#include +using namespace std; + +int main (int argc, char *argv[]) { + int a[4] = {10, 20, 30, 40}; + vector v(a, a+4); + list L(4); // Список из 4 элементов + copy(v.begin(), v.end(), inserter(L, ++(++(L.begin()))));//L.begin()); + list::iterator i; + for (i=L.begin(); i != L.end(); ++i) + cout << *i << " "; + cout << endl; + return 0; +} diff --git a/cpp/bookAmmeraal/06/main.cpp b/cpp/bookAmmeraal/06/main.cpp new file mode 100644 index 0000000..7a3d792 --- /dev/null +++ b/cpp/bookAmmeraal/06/main.cpp @@ -0,0 +1,37 @@ +/* STL */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +/* STD */ +#include +#include +#include +#include +using namespace std; + +/* Объединение вектора и массива в список +*/ + +int main (int argc, char *argv[]) { + vector a(5); + a[0] = 2; a[1] = 3; a[2] = 8; + a[3] = 20; a[4] = 25; + int b[6] = {7, 9, 23, 28, 30, 33}; + list c; // Список с начала пуст + merge(a.begin(), a.end(), b, b+6, inserter(c, c.begin())); + list::iterator i; + for (i=c.begin(); i != c.end(); ++i) + cout << *i << " "; + cout << endl; + return 0; +} diff --git a/cpp/bookAmmeraal/07/main.cpp b/cpp/bookAmmeraal/07/main.cpp new file mode 100644 index 0000000..d3ea7cb --- /dev/null +++ b/cpp/bookAmmeraal/07/main.cpp @@ -0,0 +1,45 @@ +/* STL */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +/* STD */ +#include +#include +#include +#include +using namespace std; + +// Объединяем записи, используя имена в качестве ключей + +struct entry { + long nr; + char name[30]; + bool operator<(const entry &b) const { + return strcmp(name, b.name) < 0; + } +}; + +int main (int argc, char *argv[]) { + entry a[3] = {{10, "Betty"}, + {11, "James"}, + {80, "Jim"}}, + b[2] = {{16, "Fred"}, + {20, "William"}}, + c[5], *p; + merge(a, a+3, b, b+2, c); + for (p=c; p != c+5; p++) + cout << p->nr << " " << p->name << endl; + cout << endl; + return 0; +} + diff --git a/cpp/bookAmmeraal/make_dirs.sh b/cpp/bookAmmeraal/make_dirs.sh new file mode 100755 index 0000000..43a9fae --- /dev/null +++ b/cpp/bookAmmeraal/make_dirs.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +for i in 0 1 2 3 4 5 6 7 8 9; do + for j in 0 1 2 3 4 5 6 7 8 9; do + dirname=$i$j + mkdir $dirname + cp main.cpp $dirname + done +done diff --git a/cpp/gauss_miron/gauss.cpp b/cpp/gauss_miron/gauss.cpp new file mode 100644 index 0000000..1be1519 --- /dev/null +++ b/cpp/gauss_miron/gauss.cpp @@ -0,0 +1,64 @@ +#include +#include +using namespace std; +int main() +{ +int razmer; //размер матрицы + double **a, // матрица с коэфицентами + *x, // х + *b; // свободные члены +/* Здесь переменной razmer необходимо присвоить размер матрицы */ + // создание динамических переменных + b = new double[razmer]; + x = new double[razmer]; + a = new double*[razmer]; + for(int i=0; i < razmer; i++){ + a[i] = new double[razmer]; + } +/* Здесь нам надо присвоить значения матрице а, и заполнить свободные члены b */ + + // начинаем решать) + // частный случай, если размер матрицы == 1 + if(razmer == 1){ + if(a[0][0] != 0){ + cout << "x=" << b[0]/a[0][0] << endl; + }else{ + cout << "Х любое" << endl; + } + sleep(5);//getch(); + exit(0); + } + // прямой проход + // идем слево на право по коэфицентам х + for(int k=0; k < razmer-1; k++){ + // вычитаем по строкам + for(int m=k+1; m < razmer; m++){ + // если на диагонали элемент = 0, то поменяем местами строки + if(a[m][m] == 0) exchange(a, razmer, m, get_n_no_empty(a, razmer, m)); + + double koeficent=a[m][k]/a[0][k]; + //вычисление новых коэфицентов уравнения + b[m] = b[m] - b[0] * koeficent; + for(int z=0; z < razmer; z++){ + a[m][z] = a[m][k] - a[0][k] * koeficent; + } + + } + } + // ищем решения + for(int m=razmer-1; m >= 0; m--){ + double sum=0; + // идем по строке спаво налево, считая сумму корень*коэфицент, до текущего корня + for(int i=razmer-1; i > m; i--){ + sum += x[i] * a[m][i]; + } + x[m] = (b[m] - sum)/a[m][m]; + } + + // вывод решений + cout << "###Решения:" << endl; + for(int i=0; i < razmer; i++){ + cout << "x[" << i << "]=" << x[i] << endl; + } + pause(); +} \ No newline at end of file diff --git a/cpp/gauss_miron/gauss_mir.cpp b/cpp/gauss_miron/gauss_mir.cpp new file mode 100644 index 0000000..eb061ad --- /dev/null +++ b/cpp/gauss_miron/gauss_mir.cpp @@ -0,0 +1,54 @@ +#include +using namespace std; +const int n=350; +typedef double massive[2*n+1][2*n+1]; +double a_k[2*n+1]; +double b[2*n+1]; +double c[2*n+1]; +double right_part[2*n+1]; +double sys[2*n+1][2*n+1]; +void sys_solve() +{ + int i,j,k; + double sum=0.0; + double f[2*n+1]; + massive b,c; + + //Прямой ход + for(i=0;i<2*n+1;i++) b[i][i]=1.0; + for(j=0;j<2*n+1;j++) + { + for(i=j;i<2*n+1;i++) + { + sum=0.0; + for(k=0;k=0;j--) + { + sum=0.0; + for(k=j+1;k<2*n+1;k++) sum=sum+b[j][k]*a_k[k]; + a_k[j]=f[j]-sum; + } +} + +int main() +{ + sys_solve(); + cout<<"end"<>ch; + return 0; +} diff --git a/cpp/hello/hello.cpp b/cpp/hello/hello.cpp new file mode 100644 index 0000000..a72a72e --- /dev/null +++ b/cpp/hello/hello.cpp @@ -0,0 +1,9 @@ +#include + +int main(int argc, char * argv[]) +{ + std::cout<<"Hello, world!"< +#include +#include + +// boost: разворот вектора на месте (y[0]<->y[n], y[1]<->y[n-1],...) +template +void inplace_turn(boost::numeric::ublas::vector& v) +{ + for(size_t i=0, max_i=v.size()/2, j=v.size()-1; i +void lu_solve (boost::numeric::ublas::matrix& A, boost::numeric::ublas::vector& b) +{ + using namespace boost::numeric::ublas; + + // получаем L и U на месте A + lu_factorize(A); + + // "вытаскиваем" L из A + size_t N = A.size1(); + boost::numeric::ublas::triangular_matrix L(N,N); + for(size_t i=1; i U(N,N); + for(size_t i=0; i +#include "lu_solve.hpp" + +namespace bnu=boost::numeric::ublas; + +void test1() +{ + bnu::matrix A(3,3); + A(0,0) = 1; A(0,1) = 2; A(0,2) = 3; + A(1,0) = 3; A(1,1) = 5; A(1,2) = 7; + A(2,0) = 1; A(2,1) = 3; A(2,2) = 4; + + std::cout<<"A="< v(3); + v(0) = 3; v(1) = 0; v(2) = 1; + std::cout<<"b="< +#include +#include +#include +#include +#include + +int a[ 5 ]; + +void * Thread( void* pParams ) +{ int i, num = 0; + + while ( 1 ) + { + for ( i = 0; i < 5; i++ ) a[ i ] = num; + num++; + + //~ struct timespec ts; + //~ ts.tv_sec = 0; + //~ ts.tv_nsec = 10; + //~ nanosleep(&ts,NULL); + + } +} + +int main( void ) +{ + pthread_t tr; + if(pthread_create(&tr,NULL,Thread,NULL) != 0) + return EXIT_FAILURE; + + + +// _beginthread( Thread, 0, NULL ); + + while( 1 ) + printf("%d %d %d %d %d\n", + a[ 0 ], a[ 1 ], a[ 2 ], + a[ 3 ], a[ 4 ] ); + + return 0; +} + diff --git a/cpp/multithreading/dish_ment.c b/cpp/multithreading/dish_ment.c new file mode 100644 index 0000000..ac78190 --- /dev/null +++ b/cpp/multithreading/dish_ment.c @@ -0,0 +1,4 @@ +#include + +int i; main(){for(;i["] +#include +#include +#include +#include +#include +#include +#include + + + //~ HANDLE hEvent1, hEvent2; + int key = 0x20; // Semaphore key + + int a[ 5 ]; + + void Thread( void* pParams ) + { + // Thread 2 + struct sembuf operation[1] ; + + // open semaphore + int mysemid = semget(key, 2, 0); + + operation[0].sem_op = 1; // Release on the second resource + operation[0].sem_num = 1; + operation[0].sem_flg = SEM_UNDO; + + //Release semaphore 2 + semop(mysemid, operation, 1); + + int i, num = 0; + + while ( 1==1 ) + { + WaitForSingleObject( hEvent2, INFINITE ); + for ( i = 0; i < 5; i++ ) a[ i ] = num; + SetEvent( hEvent1 ); + num++; + } + } + + int main( void ) + { +// Thread 1 + struct sembuf operation[2] ; + + // Create 2 semaphores + semid = semget(key, 2, 0666 | IPC_CREAT); + + + operation[0].sem_op = 1; //Release first resource + operation[0].sem_num = 0; + operation[0].sem_flg = SEM_UNDO; + + operation[0].sem_op = -1; // Wait on the second resource + operation[0].sem_num = 1; + operation[0].sem_flg = SEM_UNDO; + + //Release semaphore 1 and wait on semaphore 2 + // note : thread is suspended until the semaphore 2 is released. + semop(semid, operation, 2); + + // thread is released + // delete the semaphore + semctl(semid, 0, IPC_RMID , 0) + + hEvent1 = CreateEvent( NULL, FALSE, TRUE, NULL ); + hEvent2 = CreateEvent( NULL, FALSE, FALSE, NULL ); + + _beginthread( Thread, 0, NULL ); + + while( 1==1 ) + { + WaitForSingleObject( hEvent1, INFINITE ); + printf( "%d %d %d %d %d\n", + a[ 0 ], a[ 1 ], a[ 2 ], + a[ 3 ], a[ 4 ] ); + SetEvent( hEvent2 ); + } + return 0; + } + diff --git a/cpp/multithreading/mutexes.c b/cpp/multithreading/mutexes.c new file mode 100644 index 0000000..9bd0b10 --- /dev/null +++ b/cpp/multithreading/mutexes.c @@ -0,0 +1,49 @@ +#include +#include +#include +#include +#include +#include + + //~ CRITICAL_SECTION cs; +pthread_mutex_t mutex; // Mutex + + int a[ 5 ]; + + void *Thread( void* pParams ) + { + int i, num = 0; + + while ( 1==1 ) + { + //~ EnterCriticalSection( &cs ); + pthread_mutex_lock(&mutex); + for ( i = 0; i < 5; i++ ) a[ i ] = num; + //~ LeaveCriticalSection( &cs ); + pthread_mutex_unlock(&mutex); + num++; + } + } + + int main( void ) + + { + //~ InitializeCriticalSection( &cs ); + pthread_mutex_init(&mutex,NULL); + //~ _beginthread( Thread, 0, NULL ); + pthread_t tr; + if(pthread_create(&tr,NULL,Thread,NULL) != 0) + return EXIT_FAILURE; + + while( 1==1 ) + { + //~ EnterCriticalSection( &cs ); + pthread_mutex_lock(&mutex); + printf( "%d %d %d %d %d\n", + a[ 0 ], a[ 1 ], a[ 2 ], + a[ 3 ], a[ 4 ] ); + //~ LeaveCriticalSection( &cs ); + pthread_mutex_unlock(&mutex); + } + return 0; + } diff --git a/cpp/multithreading/pthread_ex.c b/cpp/multithreading/pthread_ex.c new file mode 100644 index 0000000..1b7c642 --- /dev/null +++ b/cpp/multithreading/pthread_ex.c @@ -0,0 +1,65 @@ +#include +#include +#include +#include +#include +#include + +static void wait_thread(void) +{ + time_t start_time = time(NULL); + + while (time(NULL) == start_time) + { + /* do nothing except chew CPU slices for up to one second. */ + //usleep(1); + //~ struct timespec + //~ { + //~ time_t tv_sec; /* секунды */ + //~ long tv_nsec; /* наносекунды */ + //~ }; + + //~ struct timespec ts; + //~ ts.tv_sec = 0; + //~ ts.tv_nsec = 10; + //~ nanosleep(&ts,NULL); + + } +} + +static void *thread_func(void *vptr_args) +{ + int i; + + for (i = 0; i < 10; i++) + { + fputs(" b\n", stderr); + wait_thread(); + } + + return NULL; +} + +int main(void) +{ + int i; + pthread_t thread; + + if (pthread_create(&thread, NULL, thread_func, NULL) != 0) + { + return EXIT_FAILURE; + } + + for (i = 0; i < 10; i++) + { + puts("a"); + wait_thread(); + } + + if (pthread_join(thread, NULL) != 0) + { + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} diff --git a/cpp/multithreading/pthread_ex.cpp b/cpp/multithreading/pthread_ex.cpp new file mode 100644 index 0000000..6a8c50f --- /dev/null +++ b/cpp/multithreading/pthread_ex.cpp @@ -0,0 +1,61 @@ +#include +#include +#include + +#include + +class Thread +{ +private: + pthread_t thread; + + Thread(const Thread& copy); // copy constructor denied + static void *thread_func(void *d) { ((Thread *)d)->run(); return NULL; } + +public: + Thread() {} + virtual ~Thread() {} + + virtual void run() = 0; + + int start() { return pthread_create(&thread, NULL, + Thread::thread_func, (void*)this); } + int wait () { return pthread_join (thread, NULL); } +}; + +typedef std::auto_ptr ThreadPtr; + +int main(void) +{ + class Thread_a:public Thread + { + public: + void run() + { + for (int i=0; i<20; i++, sleep(1)) + std::cout << "a " << std::endl; + } + }; + + class Thread_b:public Thread + { + public: + void run() + { + for(int i=0; i<20; i++, sleep(1)) + std::cout << " b" << std::endl; + } + }; + + ThreadPtr a( new Thread_a() ); + ThreadPtr b( new Thread_b() ); + + if (a->start() != 0 || b->start() != 0) + return EXIT_FAILURE; + + if (a->wait() != 0 || b->wait() != 0) + return EXIT_FAILURE; + + return EXIT_SUCCESS; +} + diff --git a/cpp/multithreading/pthread_ex.geany b/cpp/multithreading/pthread_ex.geany new file mode 100644 index 0000000..b970763 --- /dev/null +++ b/cpp/multithreading/pthread_ex.geany @@ -0,0 +1,43 @@ + +[indentation] +indent_width=4 +indent_type=1 +indent_hard_tab_width=8 +detect_indent=false +indent_mode=2 + +[project] +name=pthread_ex +base_path=/home/kolan/Projects/cpp/multithreading/ +description= + +[long line marker] +long_line_behaviour=1 +long_line_column=72 + +[files] +current_page=6 +FILE_NAME_0=472;C;0;16;1;1;0;/home/kolan/Projects/cpp/multithreading/asynch.c;0 +FILE_NAME_1=328;C;0;16;1;1;0;/home/kolan/Projects/cpp/multithreading/mutexes.c;0 +FILE_NAME_2=1354;C;0;16;1;1;0;/home/kolan/Projects/cpp/multithreading/semabinit.c;0 +FILE_NAME_3=642;C;0;16;1;1;0;/home/kolan/Projects/cpp/multithreading/sem08-1a.c;0 +FILE_NAME_4=2155;C;0;16;1;1;0;/home/kolan/Projects/cpp/multithreading/sem08-1b.c;0 +FILE_NAME_5=100;C;0;16;1;1;0;/home/kolan/Projects/cpp/multithreading/tmp.c;0 + +[build-menu] +CFT_00_LB=_Скомпилировать +CFT_00_CM=gcc -g -lpthread -Wall -c "%f" +CFT_00_WD= +CFT_01_LB=_Сборка +CFT_01_CM=gcc -g -lpthread -Wall -o "%e" "%f" +CFT_01_WD= +filetypes=C;C++; +EX_00_LB=_Выполнить +EX_00_CM="./%e" +EX_00_WD=%d +EX_01_LB=run +EX_01_CM= +EX_01_WD=%d +C++FT_01_LB=_Сборка +C++FT_01_CM=g++ -lpthread -Wall -o "%e" "%f" +C++FT_01_WD= diff --git a/cpp/multithreading/pthread_ex.o b/cpp/multithreading/pthread_ex.o new file mode 100644 index 0000000000000000000000000000000000000000..fbc13148510f40faa213b1c7988dc0bfc2becd1a GIT binary patch literal 14392 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 a2{Zig^ZW}2&hJf*8aTf +#include +#include +#include +#include +int main() +{ + int semid; /* IPC дескриптор для массива IPC +семафоров */ + char pathname[] = "sem08-1a.c"; /* Имя файла, + использующееся для генерации ключа. Файл с таким + именем должен существовать в текущей директории */ + key_t key; /* IPC ключ */ + struct sembuf mybuf; /* Структура для задания + операции над семафором */ + /* Генерируем IPC-ключ из имени файла 08-1a.c в текущей + директории и номера экземпляра массива семафоров 0 */ + if((key = ftok(pathname,0)) < 0){ + printf("Can\'t generate key\n"); + exit(-1); + } + /* Пытаемся получить доступ по ключу к массиву +семафоров, если он существует, или создать его из одного +семафора, если его еще не существует, с правами доступа +read & write для всех пользователей */ + if((semid = semget(key, 1, 0666 | IPC_CREAT)) < 0){ + printf("Can\'t get semid\n"); + exit(-1); + } + /* Выполним операцию D(semid1,1) для нашего массива + семафоров. Для этого сначала заполним нашу структуру. + Флаг, как обычно, полагаем равным 0. Наш массив семафоров + состоит из одного семафора с номером 0. Код операции -1.*/ + mybuf.sem_op = -1; + mybuf.sem_flg = 0; + mybuf.sem_num = 0; + if(semop(semid, &mybuf, 1) < 0){ + printf("Can\'t wait for condition\n"); + exit(-1); + } + printf("Condition is present\n"); + return 0; +} diff --git a/cpp/multithreading/sem08-1b.c b/cpp/multithreading/sem08-1b.c new file mode 100644 index 0000000..dd57c50 --- /dev/null +++ b/cpp/multithreading/sem08-1b.c @@ -0,0 +1,48 @@ +/* Программа 08-1b.c для иллюстрации работы с +семафорами */ +/* Эта программа получает доступ к одному системному семафору +и увеличивает его на 1*/ +#include +#include +#include +#include +#include +int main() +{ + int semid; /* IPC дескриптор для массива IPC + семафоров */ + char pathname[] = "sem08-1a.c"; /* Имя файла, + использующееся для генерации ключа. Файл с таким + именем должен существовать в текущей директории */ + key_t key; /* IPC ключ */ + struct sembuf mybuf; /* Структура для задания операции + над семафором */ + /* Генерируем IPC ключ из имени файла 08-1a.c в текущей + директории и номера экземпляра массива семафоров 0 */ + if((key = ftok(pathname,0)) < 0){ + printf("Can\'t generate key\n"); + exit(-1); + } + /* Пытаемся получить доступ по ключу к массиву +семафоров, если он существует, или создать его из +одного семафора, если его еще не существует, с правами доступа +read & write для всех пользователей */ + if((semid = semget(key, 1, 0666 | IPC_CREAT)) < 0){ + printf("Can\'t get semid\n"); + exit(-1); + } + /* Выполним операцию A(semid1,1) для нашего массива + семафоров. Для этого сначала заполним нашу структуру. + Флаг, как обычно, полагаем равным 0. Наш массив + семафоров состоит из одного семафора с номером 0. + Код операции 1.*/ + mybuf.sem_op = 1; + mybuf.sem_flg = 0; + mybuf.sem_num = 0; + if(semop(semid, &mybuf, 1) < 0){ + printf("Can\'t wait for condition\n"); + exit(-1); + } + printf("Condition is set\n"); + return 0; +} diff --git a/cpp/multithreading/semabinit.c b/cpp/multithreading/semabinit.c new file mode 100644 index 0000000..01b7a89 --- /dev/null +++ b/cpp/multithreading/semabinit.c @@ -0,0 +1,61 @@ +/* semabinit.c - initialize a semaphore for use by programs sema and semb */ + +#include +#include +#include +#include +#include + +/* The semaphore key is an arbitrary long integer which serves as an + external identifier by which the semaphore is known to any program + that wishes to use it. */ + +#define KEY (1492) + +int main() +{ + int id; /* Number by which the semaphore is known within a program */ + + /* The next thing is an argument to the semctl() function. Semctl() + does various things to the semaphore depending on which arguments + are passed. We will use it to make sure that the value of the + semaphore is initially 0. */ + + union semun { + int val; + struct semid_ds *buf; + ushort * array; + } argument; + + argument.val = 0; + + /* Create the semaphore with external key KEY if it doesn't already + exists. Give permissions to the world. */ + + id = semget(KEY, 1, 0666 | IPC_CREAT); + + /* Always check system returns. */ + + if(id < 0) + { + fprintf(stderr, "Unable to obtain semaphore.\n"); + exit(0); + } + + /* What we actually get is an array of semaphores. The second + argument to semget() was the array dimension - in our case + 1. */ + + /* Set the value of the number 0 semaphore in semaphore array + # id to the value 0. */ + + if( semctl(id, 0, SETVAL, argument) < 0) + { + fprintf( stderr, "Cannot set semaphore value.\n"); + } + else + { + fprintf(stderr, "Semaphore %d initialized.\n", KEY); + } + return 0; +} diff --git a/cpp/multithreading/time_test.c b/cpp/multithreading/time_test.c new file mode 100644 index 0000000..444f9d4 --- /dev/null +++ b/cpp/multithreading/time_test.c @@ -0,0 +1,29 @@ +#include +#include +#include + +int main(int argc, char * argv[]) +{ + //~ int i = 0; + //~ for ( i = 0; i < 10; i++ ) + //~ { + //~ printf("%llu \n", (unsigned long long)time(NULL)); + //~ sleep(1); + //~ } + + printf("sizeof(ssize_t) = %lu\n", sizeof(ssize_t)); + + time_t now; + struct tm *ts; + char buf[80]; + + /* Get the current time */ + now = time(NULL); + + /* Format and print the time, "ddd yyyy-mm-dd hh:mm:ss zzz" */ + ts = localtime(&now); + strftime(buf, sizeof(buf), "%a %Y-%m-%d %H:%M:%S %Z", ts); + printf("%s\n", buf); + + return 0; +} diff --git a/cpp/multithreading/time_test.o b/cpp/multithreading/time_test.o new file mode 100644 index 0000000000000000000000000000000000000000..2f5afbe6c54bc1ffa2cf90712cde44e6afa89b8f GIT binary patch literal 4952 zcmbtXU2GIp6uvXFZI|x0EG>TqVg_-s#CEnMprk^nsmL}diV`%KXr0~8c2{<1mYvx` z8%>EO;0h?k=#v^_q9HyQG)jmufFY4+Oyofy@W~ev9(cf*7!r+m&b{YOcW;LmJ;}~F z-*F5-h**~ZRW*^}^TT#@*8_W17GUt0GqnJ|f%Fd1uG$&Buy#3PBZUdGy&LM$2`8yKp1 zuV%y(33O`!mvn`(TRR!+w6q;bk^De%tQQ9yX~(!kTNtN9Tyirr;$jGdU7CiqyVt=G znFLJwB6L*;4de0tMm3qc@u9~%xYA$|fOLUkMDnfB^)~bwv9^*MKmtdxcn8<|J1>B* zJwAik8jo*}9|h2Xj7S_Wf*B7gY^!l}8_Z@2KxQ0!7M}WgLaz%H6TXH(ae>|tC@Ii! zfl>mU5NNqTCk0w9(3=9S73eL2Oo2}0wDt9U0=<2Nqe0dwI@YFPaFl!s0oY`wwPA=c ze`1axdW`uab4k}b#I)3L@app~CIcT%(OK~6^TlMYUSL|!IUadx4%+5JRD1kgcy?jG zx*d2t$=Ea~ojn6jP5Z063!ePNfjli!_iLGwn=jWVolLF-<(nDCf>Onq2pm7K@{rDg znX2PkMSRoH0~S9TOT+*=fByn>oAUAnsvNFpO1PX*l2Dy)8%?6OWS68 z|3JDjke)Qt*`f6Aq4Zue{TzOzSd~!-G<> zOD=c!hc13h!xULAB*+LV6Ne`48D`g}rdg)wRh-NLuWY-SJvHwoCm;Bke6^aX)XPCB zDApW%vgA%NNGf{u8tPfkby(f?OH-~hY37SIXQwKGS17Qu=T4cS6W$TL2RT~F*YN6pRFW@`(t?71{JP6O*W zFjYQ5KCjmKS8x!vYjkwT?AztIf#-=zW_6P_*l$)#&cGm6-be$8W-h0mYO_x>?Qlw4 zlkA9}g3VbAJbqC4K0Ml;8a=9a@$Ud6Eq|sG*g4QaP3WSuYEId<0_SkRtVuhtnU(W> zFr8d|YQoOtYR)vXc#NP*Zoz9I$|cwztLBMh5mff_Eiu)4&b2EJ)NQI{*KBtRIgtbN zVOHL&RG=Hoa=pN@pu+=xVCN4|o>QDC)SwQo=zoa`+4!1-{h?|jq}8)5Um0?^>2_ChW*1mQv0_LIJG8Fte^5`5j2S!i?@xa@qgmUH-v$nAhTq&^qkKZ+X9NtN>i8w_s2m3WLiyuirZCi4{C!e6j9f>H!t>cIYHR?` zsP*5DSbq{?)%Cv#oLUpd+eSqP5j2S!+W=qG_$jzNp~!sfKV0q>jsHGySX0J<$)zmU zuM8-m)Mp?%D*qV2Br*0N)ssr*N&PwHOTW}#P`<=c%RGs{0|Pnr{G6x!tum0b?7yVH z1tY3|BhRV@JF!;j| zA%?iqF7g)caT$yb&mtaAORIDN>}l%fL2_ed+;3Ix0V0aO z_bz+y#ekR1#VR9a9LlN6YhjOqhPZ8@BxCy z7+3%I9U=Wlf*_A;mHaj&L6FBTN`4GU5LqAJ2NZc($9TNc$@l^~L6BboAIalyAPUxL zK7H~;AdmJn_@Kxgll*Bx^O|T%9`_Li_XkCNuh$7Wdj}-m`!ePh}Ha`Y(t$HbcoFZ*jL{C0{T zR`?%?A0r+Wo@pshDZD&a`lahu;GX=A9gu|LvA RUVdk(bxd@EVD0Am{{nwb!Jz;E literal 0 HcmV?d00001 diff --git a/cpp/multithreading/tmp.c b/cpp/multithreading/tmp.c new file mode 100644 index 0000000..e5ae04e --- /dev/null +++ b/cpp/multithreading/tmp.c @@ -0,0 +1,12 @@ +#include +#include +#include +#include +#include + +int main(int argc, char * argv[]) { + + printf("sizeof(key_t) = %lu\n", sizeof(key_t)); + //~ printf("SEMMSL = %lu\n", SEMMSL); + return 0; +} diff --git a/cpp/multithreading/udp_socket.c b/cpp/multithreading/udp_socket.c new file mode 100644 index 0000000..2fa5cc5 --- /dev/null +++ b/cpp/multithreading/udp_socket.c @@ -0,0 +1,62 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +volatile int is = 1; + +void sig_int(int sig_no) +{ + is = 0; + return; +} + +int main() +{ int sock, len; + struct sockaddr_in addr; + char buff[256]; + + if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) + { + fprintf(stderr, "%d ", errno); + perror("socket()"); + return 1; + } + + addr.sin_family = AF_INET; + addr.sin_addr.s_addr = INADDR_ANY; + addr.sin_port = htons(10000); + + signal(SIGINT, sig_int); + + if (bind(sock, (struct sockaddr*)&addr, sizeof(struct sockaddr_in)) == -1) + { + fprintf(stderr, "%d ", errno); + perror("bind()"); + } + + while(is) + { memset(buff, 0, 256); + len = sizeof(struct sockaddr_in); + memset(&addr, 0, sizeof(struct sockaddr_in)); + if (recvfrom(sock, buff, 255, 0, (struct sockaddr*)&addr, &len) == -1) + { + fprintf(stderr, "%d ", errno); + perror("recvfrom()"); + } + addr.sin_addr.s_addr = htonl(addr.sin_addr.s_addr); + addr.sin_port = htons(addr.sin_port); + printf("%d.%d.%d.%d:%d (%d) > %s\n", (addr.sin_addr.s_addr >> 24), + ((addr.sin_addr.s_addr >> 16) & 0xff), + ((addr.sin_addr.s_addr >> 8) & 0xff), + (addr.sin_addr.s_addr & 0xff), addr.sin_port, len, buff); + } + + close(sock); + return 0; +} + diff --git a/cpp/sockets/echo-client.c b/cpp/sockets/echo-client.c new file mode 100644 index 0000000..5093ce6 --- /dev/null +++ b/cpp/sockets/echo-client.c @@ -0,0 +1,62 @@ +#include +#include +#include +#include + +#include +#include +#include + +unsigned int ip2int(const char * s) { + int ip[4]; + sscanf(s,"%d.%d.%d.%d",ip,ip+1,ip+2,ip+3); + return ip[0]<<24|ip[1]<<16|ip[2]<<8|ip[3]; +} + +int sendall(int s, char *buf, int len, int flags) +{ + int total = 0; + int n; + + while(total < len) + { + n = send(s, buf+total, len-total, flags); + if(n == -1) { break; } + total += n; + } + + return (n==-1 ? -1 : total); +} + +char message[] = "Hello there!\n"; +char buf[sizeof(message)]; + +int main() +{ + int sock; + struct sockaddr_in addr; + + sock = socket(AF_INET, SOCK_STREAM, 0); + if(sock < 0) + { + perror("socket"); + exit(1); + } + + addr.sin_family = AF_INET; + addr.sin_port = htons(3425); // или любой другой порт... + addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); // (ip2int("192.168.2.1")); + if(connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) + { + perror("connect"); + exit(2); + } + + send(sock, message, sizeof(message), 0); + recv(sock, buf, sizeof(message), 0); + + printf("%s\n",buf); + close(sock); + + return 0; +} diff --git a/cpp/sockets/echo-server.c b/cpp/sockets/echo-server.c new file mode 100644 index 0000000..d68930b --- /dev/null +++ b/cpp/sockets/echo-server.c @@ -0,0 +1,65 @@ +#include +#include +#include +#include + +#include +#include +#include + +static const char * int2ip(unsigned int ip) { + static char s[16]; + sprintf(s,"%d.%d.%d.%d",ip>>24,ip<<8>>24,ip<<16>>24,ip<<24>>24); + return s; +} + +int main() +{ + int sock, listener; + struct sockaddr_in addr; + char buf[1024]; + int bytes_read; + + listener = socket(AF_INET, SOCK_STREAM, 0); + if(listener < 0) + { + perror("socket"); + exit(1); + } + + addr.sin_family = AF_INET; + addr.sin_port = htons(3425); + addr.sin_addr.s_addr = htonl(INADDR_ANY); + if(bind(listener, (struct sockaddr *)&addr, sizeof(addr)) < 0) + { + perror("bind"); + exit(2); + } + + listen(listener, 1); + //~ printf("%X\n",addr.sin_addr.s_addr); + while(1) + { + socklen_t n = sizeof(struct sockaddr); + sock = accept(listener, (struct sockaddr *)&addr, &n); + printf("incoming request from %s\n",int2ip(ntohl(addr.sin_addr.s_addr))); + //~ printf("%X\n",addr.sin_addr.s_addr); + if(sock < 0) + { + perror("accept"); + exit(3); + } + + while(1) + { + bytes_read = recv(sock, buf, 1024, 0); + if(bytes_read <= 0) break; + send(sock, buf, bytes_read, 0); + printf("%s", buf); + } + + close(sock); + } + + return 0; +} diff --git a/cpp/sockets/int2ip.c b/cpp/sockets/int2ip.c new file mode 100644 index 0000000..eccdb22 --- /dev/null +++ b/cpp/sockets/int2ip.c @@ -0,0 +1,33 @@ +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include + +static const char * int2ip(unsigned int ip) { + static char s[16]; + sprintf(s,"%d.%d.%d.%d",ip>>24,ip<<8>>24,ip<<16>>24,ip<<24>>24); + return s; +} + +int main(int argc, char * argv[]) { + if(argc < 2) { + perror("need hex ip address"); + exit(1); + } + + unsigned int ip = 0; + sscanf(argv[1],"%X",&ip); + + printf("%s\n",int2ip(ip)); + + return 0; +} diff --git a/cpp/sockets/ip2int.c b/cpp/sockets/ip2int.c new file mode 100644 index 0000000..7b44472 --- /dev/null +++ b/cpp/sockets/ip2int.c @@ -0,0 +1,30 @@ +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include + +unsigned int ip2int(const char * s) { + int ip[4]; + sscanf(s,"%d.%d.%d.%d",ip,ip+1,ip+2,ip+3); + return ip[0]<<24|ip[1]<<16|ip[2]<<8|ip[3]; +} + +int main(int argc, char * argv[]) { + if(argc < 2) { + perror("need ip address string"); + exit(1); + } + + printf("%X\n",ip2int(argv[1])); + + return 0; +} diff --git a/cpp/sockets/sock1.c b/cpp/sockets/sock1.c new file mode 100644 index 0000000..27c255c --- /dev/null +++ b/cpp/sockets/sock1.c @@ -0,0 +1,67 @@ +#include +#include +#include + +//~ domain = AF_UNIX, AF_INET, AF_INET6, AF_IPX +//~ type = SOCK_STREAM, SOCK_DGRAM, SOCK_RAW +//~ int socket(int domain, int type, int protocol); + +//~ struct sockaddr { + //~ unsigned short sa_family; // Семейство адресов, AF_xxx + //~ char sa_data[14]; // 14 байтов для хранения адреса +//~ }; +//~ struct sockaddr_in { + //~ short int sin_family; // Семейство адресов + //~ unsigned short int sin_port; // Номер порта + //~ struct in_addr sin_addr; // IP-адрес + //~ unsigned char sin_zero[8]; // "Дополнение" до размера структуры sockaddr +//~ }; +//~ struct in_addr { + //~ unsigned long s_addr; +//~ }; +//~ htons, htonl, ntohs, ntohl +//~ int bind(int sockfd, struct sockaddr *addr, int addrlen); + +//~ int listen(int sockfd, int backlog); +//~ int accept(int sockfd, void *addr, int *addrlen); + +// клиент +//~ int connect(int sockfd, struct sockaddr *serv_addr, int addrlen); + +//~ int send(int sockfd, const void *msg, int len, int flags); + +// отправка буфера целиком +//~ int sendall(int s, char *buf, int len, int flags) +//~ { + //~ int total = 0; + //~ int n; +//~ + //~ while(total < len) + //~ { + //~ n = send(s, buf+total, len-total, flags); + //~ if(n == -1) { break; } + //~ total += n; + //~ } +//~ + //~ return (n==-1 ? -1 : total); +//~ } + +//~ int recv(int sockfd, void *buf, int len, int flags); + +// закрытие соединения +//~ int close(int fd); + +// запрет передачи 0 - чтения, 1 - записи, 2 - и того, и др. +//~ int shutdown(int sockfd, int how); + + +int main(int argc, char * argv[]) +{ + struct a + { + char aaa[256]; + }; + + printf("%lu\n", sizeof(struct a)); + return 0; +} diff --git a/cpp/sockets/tmp1.c b/cpp/sockets/tmp1.c new file mode 100644 index 0000000..e41de65 --- /dev/null +++ b/cpp/sockets/tmp1.c @@ -0,0 +1,25 @@ +#include + +void f() +{ + int c = 0; + printf("c=%lu\n",(unsigned long)&c); +} + + +int main(int argc, char * argv[]) { + //~ printf("%lu\n", sizeof(long)); + + int a = 0; + + int pid = fork(); + printf("pid=%d\n",pid); + printf("a=%lu\n",(unsigned long)&a); + + int b = 0; + printf("b=%lu\n",(unsigned long)&b); + + f(); + + return 0; +} diff --git a/cpp/wstring/wstring.cpp b/cpp/wstring/wstring.cpp new file mode 100644 index 0000000..856e937 --- /dev/null +++ b/cpp/wstring/wstring.cpp @@ -0,0 +1,26 @@ +// Filename : string_wstring.cpp +// Author : A.G.Raja +// License : GPL +// Website : http://agraja.wordpress.com + +#include + +using namespace std; + +string wstring2string(wstring wstr) { +string str(wstr.length(),' '); +copy(wstr.begin(),wstr.end(),str.begin()); +return str; +} + +wstring string2wstring(string str) { +wstring wstr(str.length(),L' '); +copy(str.begin(),str.end(),wstr.begin()); +return wstr; +} + +int main() { + wstring wstr = string2wstring("raja"); + string str = wstring2string(wstr); + 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 +int main( int argc, char *argv[]) +{ + /* Объявляем виджеты */ + GtkWidget *label; // Метка + GtkWidget *window; // Главное окно + /* Инициализируем GTK+ */ + gtk_init(&argc, &argv); + /* Создаем главное окно */ + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + /* Устанавливаем заголовок окна "Здравствуй, мир!" */ + gtk_window_set_title(GTK_WINDOW(window), "Здравствуй, мир!"); + /* Создаем метку с текстом "Здравствуй, мир!" */ + label = gtk_label_new("Здравствуй, мир!"); + /* Вставляем метку в главное окно */ + gtk_container_add(GTK_CONTAINER(window), label); + /* Показываем окно вместе с виджетами */ + gtk_widget_show_all(window); + /* Соединяем сигнал завершения с выходом из программы */ + g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL); + /* Приложение переходит в вечный цикл ожидания действий пользователя */ + gtk_main(); + return 0; +} diff --git a/java/helloworld1/.classpath b/java/helloworld1/.classpath new file mode 100644 index 0000000..233be1d --- /dev/null +++ b/java/helloworld1/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/java/helloworld1/.project b/java/helloworld1/.project new file mode 100644 index 0000000..9041b79 --- /dev/null +++ b/java/helloworld1/.project @@ -0,0 +1,17 @@ + + + helloworld1 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/java/helloworld1/hello.class b/java/helloworld1/hello.class new file mode 100644 index 0000000000000000000000000000000000000000..c92c6bc6d2f16a269ea2c628f9b750d6331c4df2 GIT binary patch literal 518 zcmZutOHaZ;5dH>=rL_ox;9J2H7-Qqf1ICMq@zAIVhKr{KHn5}*Q;No)r3Xzs_yhb= z#@S**NVv@G%N&u!`J!Mkb7xB53EaNhsXt zwNC0UQS1*IHny>AVuw&kFc+w=y+Fa&|J&SnAOH`IvCfJ>58u#V3(l@Zv zHBYq^8eq44Zy>`jJ{m`pE0;5I&K-Xu|CWwzj(V)Wu5xr{A2=7dvap6CcQp7sCF9;Z eO6A%Iw&nyjj{pOC)|!)8IKUzI33ZMcH2wg9P-p}I literal 0 HcmV?d00001 diff --git a/java/helloworld1/hello.java b/java/helloworld1/hello.java new file mode 100644 index 0000000..acb167a --- /dev/null +++ b/java/helloworld1/hello.java @@ -0,0 +1,6 @@ +import java.util.*; +public class hello { + public static void main(String[] args) { + System.out.print("Hello, world!"); + } +} diff --git a/nasm/div/2.asm b/nasm/div/2.asm new file mode 100644 index 0000000..1321ad0 --- /dev/null +++ b/nasm/div/2.asm @@ -0,0 +1,37 @@ + +BITS 32 + +GLOBAL divover + +SECTION .text + +mem dd 01h + +divover: + + mov eax, [esp+4] + mov ecx, [esp+8] + + mov ebx, mem + mov [ebx], ecx + + div ebx + ret + +; mov eax, [esp+4] ; n в eax +; cmp eax, 1 +; je ret1 ; 1 ! = 1 +; +; push ecx ; save used ecx +; +; dec eax ; eax = n-1 +; push eax +; call fact ; в eax (n-1)! +; pop ecx ; ecx = n +; inc ecx +; mul ecx ; eax *= ecx +; +; pop ecx ; restore used ecx +; +;ret1: +; ret diff --git a/nasm/div/2.c b/nasm/div/2.c new file mode 100644 index 0000000..f372d34 --- /dev/null +++ b/nasm/div/2.c @@ -0,0 +1,16 @@ + +#include + +typedef unsigned int T; + +extern T divover(T m, T n); + +int main ( int argc, char * argv[] ) { + + T m = atoi(argv[1]), n = atoi(argv[2]); + + printf ( "Остаток от деления %d на %d равен %d", m, n, divover(m,n)); + + return 0; +} + diff --git a/nasm/div/2.o b/nasm/div/2.o new file mode 100644 index 0000000000000000000000000000000000000000..b02678f946afbe1a1f7b82745c69f8226156b320 GIT binary patch literal 512 zcmb<-^>JflWMqH=Mh0dE1doBi0V-hvrZpJY7?@y6Nuoh!f-oCYmjRF?hGc>Ol+6yL znUTZ;fa@3)nG52B*xfEFEZsgT9J_&RhEDG9pAUl=P@q?mT2aEFSDaB?QdE+d1Y}j_ zLTD(zC^ZM72Brgr2AK~7EDRt2!`L7i6f>akK>$VuZXgHbHV_a1xz0#0u{f6@H#L_b VC9^EQEVT$C2P1ib3`V4Y0|0# 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 F@Nd${1D5~* literal 0 HcmV?d00001 diff --git a/nasm/fact/1.asm b/nasm/fact/1.asm new file mode 100644 index 0000000..693735f --- /dev/null +++ b/nasm/fact/1.asm @@ -0,0 +1,26 @@ + +BITS 32 + +GLOBAL fact + +SECTION .text + +fact: + + mov eax, [esp+4] ; n в eax + cmp eax, 1 + je ret1 ; 1 ! = 1 + + push ecx ; save used ecx + + dec eax ; eax = n-1 + push eax + call fact ; в eax (n-1)! + pop ecx ; ecx = n + inc ecx + mul ecx ; eax *= ecx + + pop ecx ; restore used ecx + +ret1: + ret diff --git a/nasm/fact/1.c b/nasm/fact/1.c new file mode 100644 index 0000000..d730aa4 --- /dev/null +++ b/nasm/fact/1.c @@ -0,0 +1,16 @@ + +#include + +extern int fact(int n); + +int main ( int argc, char * argv[] ) { + + int n = atoi(argv[1]); + + n = fact(n); + + printf ( "%d", n ); + + return 0; +} + diff --git a/nasm/fact/1.o b/nasm/fact/1.o new file mode 100644 index 0000000000000000000000000000000000000000..0e5acb0a27982114c244213d5c6612e7a7841f03 GIT binary patch literal 624 zcmb<-^>JfjWMqH=Mg}_u1P><4z~F#jLfH-stPD&@qU13_c7ZS(n)U{$BgE0f1K(7s$UUJ4k`>66$G-d`QidpVFgqr3y_9kkdOpaToOoQvp)c8D9C(dfNp=c ziwaBg55^MSK#zbI@Bjb*AL;o0VdPwqLRcUAgeMLLPPinm3Ubo yds!Gh{>P?>8B2`wfE6+_h@oi!g|`3}^>Af|dWprk3~7nUB@9KWC5CWuC<6dk$0QU0 literal 0 HcmV?d00001 diff --git a/nasm/fact/build.sh b/nasm/fact/build.sh new file mode 100755 index 0000000..f9de687 --- /dev/null +++ b/nasm/fact/build.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +target=1 + +rm -f $target +nasm -f elf64 ${target}.asm +gcc -o ${target} ${target}.c ${target}.o +for i in 1 2 3 4 5 6 7 8 9 10 11 12 ; do +echo "fact($i) = `./${target} $i`" +done diff --git a/nasm/flags/build.sh b/nasm/flags/build.sh new file mode 100644 index 0000000..8849a1d --- /dev/null +++ b/nasm/flags/build.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +target=flags + +rm -f $target +nasm -f elf ${target}.asm +gcc -o ${target} ${target}.c ${target}.o +for i in 1 2 3 4 5 6 7 8 9 10 11 12 ; do +echo "fact($i) = `./${target} $i`" +done + + diff --git a/nasm/flags/flags b/nasm/flags/flags new file mode 100644 index 0000000000000000000000000000000000000000..b0d5c7750ad6d6705cfae5f7617616b16fb22079 GIT binary patch literal 4145 zcmb7HU2IfE6rTM7subMvXVoTdv5k=#Ds_sB_;CnUSqeKbU@0+<(ZVM!Ol5@|T zIp3T)GjrzWzS-2)914Ymrm%HbA3k zsEdLlv_Y>QfE_#+I+-^5CQD*la1;&6Y%gNUF6%ykjf@7BVD?LU7@`{BYS_r9p_6H6 zALI?dZ$RJVICQeMb^PL{px#CtDlz-!NA25;tXQnMYp2((_W;40|-G-AlmaBS% zCdbyY@p;*taWbZRz?>77IY!pApQ%I)!oH1yb#Yi%1Q2sjeh_^9ZOjv7m6$D-OtCMU zq6^dP>CNX%$F&NsX$lM{$ziM%W@|fYQ<MG<6$Z<+c%5_Q%;szxq>iMBx zienY!VKggy@&oXhQQ@s91K}+k!R&*IoS?ejUmp6occ?(iaHRw)6SYwq&foMr>6fk~p-FTN6VRR2v0+pB zcX-;`@Yl~y3J2dAzUA zShhr!g)p2wy{@$b(k&>N)+L+~cA-xgxx8x|4eMH$x>k=c(w37JMruzE4V82Y!syBM z8@ud+lgZ~MDJEsz?sg^q&pp*IDUJO-F%72g#0mF6RI?8(u3fD>#ZKOxRyhn(W z_YVwllr`ydzYZ1pE?_>TfqNWv+D=Jc1!hjsAM@-0aNAL4TNEXR`SuK$xkeoGavVnH zqb6cWJcF52#4(?mQDBbiepydWfSH4`3|s<*IO>A^LKR6c?>FL@$1Vy?Htmm+dKRp4 z%=^8*KiWAyjq695v2tH=-yH;wdqtD>+lLB`I||%U;5KOxByr@|!5YUmO$?KCniW2A z?nnb*jpIJQfW|e_qCUFccYGYW6XU>*!@&48Y216Lpg-coAod?7PTN?e%O9ak9M_H~ z8Q(nBztgtEr*im1E`?vntHx5B);^!piboMZOO^MUWF(+`>|~y^ z^rdMLaNlbMk{A-DTr;T&u^o%M9Synv<6w?~Im28I`Wu-o#H-o~Y=I)Q$;9)6HR`3U z&IzTfo_QW9UG>0yuXOgV_P5g2YUz6+B3Bf97yCikc@n98sdQN_?;WLc6l$L-owt|} z+)qkZnazEpbeqTTb6kQiiiaiGG8bolTHrm)sxmGDz15I28ia`Uh{aSKZSiQD{wOM zk;r_e9tzJF1|;_>brFuqb2q4WqFUd#q3~SMMVudB9PxES<-3wAHwXTALF)OX{sweS zaTMOw3MBPIV4ge71itmT-+5j^z~3zKISW2uHU+`;knjE!S{mt-_bumNvGeG?~sY=N&ivi zv%AbryC>t|J=B=B9LIKq+1+QRUxVQD<+gvQwQFzvL{0hkGR;Z-r<}Z*wsNVg4KM2x z?VV=R#`XAj^IbAB`C3xHY(c;LdkgB_R? + +extern int fact(int n); + +int main ( int argc, char * argv[] ) { + + int n = atoi(argv[1]); + + n = fact(n); + + printf ( "%d", n ); + + return 0; +} + diff --git a/nasm/flags/flags.o b/nasm/flags/flags.o new file mode 100644 index 0000000000000000000000000000000000000000..18a8d8e2b6cc8cba9368f2fa18844ad84fc6d61c GIT binary patch literal 464 zcmb<-^>JflWMqH=Mh0dE1doBi0V-hvrZpH?8JJ*7Nuoh!f-oCYmjI9>iDZHRl+6yL znUTZ|fa(;H_#iVtKoE$LU6KHl2mp$)AYqW1AUlxF+W=H23KW9@n0YXMw~GpkEl9A0 zH_#*C#oPb?|3^B0e;9cfra-SGwW5SUuQ;Q)q^Kk@3COC_%>a}G>Q2i^OfS|;EY4*}OH3|dC`v6cL{h>400e|1KL7v# literal 0 HcmV?d00001 diff --git a/nasm/lnxhello/build.sh b/nasm/lnxhello/build.sh new file mode 100644 index 0000000..11c9e27 --- /dev/null +++ b/nasm/lnxhello/build.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +target=lnxhello + +rm -f $target +nasm -f elf ${target}.asm +gcc -o ${target} ${target}.c ${target}.o +./${target} + diff --git a/nasm/lnxhello/lnxhello.asm b/nasm/lnxhello/lnxhello.asm new file mode 100644 index 0000000..7bc8ff0 --- /dev/null +++ b/nasm/lnxhello/lnxhello.asm @@ -0,0 +1,49 @@ +; +; Assembly "Hello, World!" for Linux +; + + +; Properly defined in +%define SYS_exit 1 +%define SYS_write 4 + + section .text + + global _start +_start: + ; gdb doesn't like to stop at the entry point address, so + ; we put a nop here for pure convenience + nop + + +write_hello: + mov edx, hello_len + mov ecx, hello + +.loop: + mov eax, SYS_write + mov ebx, 1 ; stdout + int 80h + + cmp eax, -4096 + ja error + + add ecx, eax + sub edx, eax + jnz .loop + +ok: + mov eax, SYS_exit + xor ebx, ebx + int 80h + hlt + +error: + mov eax, SYS_exit + mov ebx, 1 ; Error + int 80h + hlt + + section .rodata +hello: db "Hello, World!", 10 +hello_len equ $-hello diff --git a/nasm/lnxhello/lnxhello.o b/nasm/lnxhello/lnxhello.o new file mode 100644 index 0000000000000000000000000000000000000000..6a2aae6f020ccdd3882bad6a7183cf089f2e8fbc GIT binary patch literal 768 zcmbVKJ5B>J5FLj=_(+h3f{sWOAfc7`RR{?R5EAs1VNq5J!ikaBD4`-p;0QTF$^aGg zIROWtO{Db88?Vipf`*Z1-@KXUvDf3L)5|j<1bGuQLj@x`c7=V5n^ZylKgK=T=iK6J zki(!+)x{Mc>q?IIL6%+2PqO>S+vl&3|1YkW zX_AGy-!Fmhr$nm|6l;XNx22y&f_4#a1pEMT6!387Jed>Jiuq2mBIdbZC)w^c`3|Bu pZBacnu{PAvwnew("tcp",1,1); + if ($p->ping($host)) { + print "$host\n"; + } + $p->close(); +} + +sub startthreads { + foreach (@ipaddr) { + sleep(0); + push(@pinged_addr, threads->create("startping", $_)); + } + + foreach (@pinged_addr) { + $_->join(); + } +} + +@ipaddr = subnetting($subnet, @hosts); +startthreads(@ipaddr); diff --git a/perl/study0.pl b/perl/study0.pl new file mode 100644 index 0000000..96dbe4f --- /dev/null +++ b/perl/study0.pl @@ -0,0 +1,111 @@ +#!/usr/bin/perl + +# print "X p |-o -- x P I-O, world!\n" +#$NAMe = 'Johnny'; +#$AGe=33; +#@BOOK=('Introduction', 'First Chapter', 'Second Chapter'); +#%StaR_waRs_family=('faTher','Anakin','Mother','Padme','Male twin','Luke','Female twin','Leina'); +#print $StaR_waRs_family{'faTher'}; + +#print "\n"; + +#$res=`ls /usr/bin`; +#print $res + +#$a='Hello'; +#$b='$a, world!'; +#$c="$a, world!"; + +#print $b,"\n"; +#print $c,"\n"; + +#%StarWarsFamily=( +# 'Father',{'Name','Anikin', +# 'Height(cm)',210, +# 'jobs',{'Slave','Podracer pilot','Jedi Knight','Darth Vader'}}, +# 'Mother',{} # другие такие же данные... +#); +#print "$StarWarsFamily{'Father'}{'jobs'}{'Slave'}\n"; + +#print `date` + +#$A=10*7.5-16; +#$b=$A%4; +#print "A = ",$A,"\nB = ",$b,"\n"; + +#$A++; +#$b-=9; +#print "A = ",$A,"\nB = ",$b,"\n"; + +#$s="act&"; +#$s++; +#print $s,"\n"; + +#$a="Luke"; $b="Skywalker"; +#$c=$a." ".$b; +#print "$c " x 3,"\n"; + +#$a=2; $b=3; +#print $a cmp $b; + +#if('dude' lt 'hello') {print "dude";} +#if('dude' < 'hello') {print "hello";} + +#@Jedi=("Yoda","Obi Wan"); +#push(@Jedi,"Anakin"); +#print $Jedi[2]."\n"; +#pop(@Jedi); +#print $Jedi[2]."\n"; + +#%days=('January',31,'February',28.25,'Mart',31,'April',30, +# 'May',31,'June',30,'July',31,'August',31,'September',30,'October',31, +# 'November',30,'December',31); +#while (($a,$b)=each %days) {print $a,": ",$b,"\n";} + +#@A=keys (%days); +#print $A[1]."\n"; + +#($x,$y,$z)=($y,$z,$x); +#($Name,$Surname,$Address)=('Kolan','Shashkin','Bratskaya,5a'); +#($var,$arr)=('Переменная','m1','m2','m3'); + +#@a=(0,1,2,3); +#for($i=0;$i<7;$i++) {print $a[$i]."\n";} +#splice(@a,2,0,('a','b')); +#for($i=0;$i<7;$i++) {print $a[$i]."\n";} + +#@a=(34,2,553,2,15); +#@a=sort (@a); #@a=sort AS_I_WANT (@a); +#for($i=0;$i<10;$i++){print $a[$i]."\n";} + +#@a = ; +#for($i=0;$i<10;$i++){print $a[$i];} + + +#%hash=('a','b','c','d'); +#print $hash{'c'}."\n"; +#delete($hash{'c'}); +#print $hash{'c'}."\n"; + +#%a=('a','1','b',$_,'c','3'); +#if (defined $a{'b'}) {print "defined ;)\n";} +#else {print "undefined ;(\n";} +#print $a{'b'}."\n"; + + +# Вопрос: Что будет без m в выражении m/hello/ +#$string=; +#if($string =~ m/^hello$/) {print "Yes\n";} else {print "No\n";} +#$string =~ s/a/A/g; # g указывает на глобальное изменение +#print $string."\n"; + +#$jedi='Anakin'; +#$jedi=~s/Master $jedi/t he future Darth Vader/g; +#s/Master (Obi-Wan|Yoda)/t he Jedi Knight $1/; +#print $jedi."\n"; + +$s='Hello, world! My name is hello!'; +$s =~ s/(Hello|hello)/ghm $1/g; +print $s."\n"; + + diff --git a/php/ftrunc.php b/php/ftrunc.php new file mode 100644 index 0000000..228f606 --- /dev/null +++ b/php/ftrunc.php @@ -0,0 +1,47 @@ +#!/usr/bin/php + +# +# This program is free software: you can redistribute it and/or modify it under the terms of +# the GNU General Public License version 3 as published by the Free Software Foundation. +# See http://www.gnu.org/licenses/gpl-3.0.html for more details. + +$file = $argv[1]; +$size = $argv[2]; +$unit = $argv[3]; + +if((trim($file)=="") || (!is_numeric($size))) + die ("Usage:\n ftrunc.php \n"); + +switch ($unit) { + case "K": + $size_b = $size*1024; break; + case "M": + $size_b = $size*1024*1024; break; + case "G": + $size_b = $size*1024*1024*1024; break; + case "T": + $size_b = $size*1024*1024*1024*1024; break; + default: + $unit = ""; + $size_b = $size; +} + +echo "File: $file\n"; + +if($unit!="") { + echo "New size: $size $unit ($size_b bytes)\n"; +} else { + echo "New size: $size_b bytes\n"; +} + +$fh = fopen($file, "a"); +if($fh===false) die("Unable to open file for writing."); + +echo "Truncating... "; +if(ftruncate($fh, $size_b)) echo "Done.\n"; else echo "FAILED.\n"; + +fclose($fh); + +?> diff --git a/php/strtotime b/php/strtotime new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/php/strtotime @@ -0,0 +1 @@ + diff --git a/php/strtotime.php b/php/strtotime.php new file mode 100644 index 0000000..816152e --- /dev/null +++ b/php/strtotime.php @@ -0,0 +1,4 @@ +#!/usr/bin/php + diff --git a/prolog/parents.pl b/prolog/parents.pl new file mode 100644 index 0000000..468ca6b --- /dev/null +++ b/prolog/parents.pl @@ -0,0 +1,24 @@ +parent(abraam,isaak). +parent(abraam,petr). +parent(isaak,havriil). +parent(isaak,olga). +parent(petr,stefan). +parent(rohima,havriil). +parent(rohima,olga). +parent(havriil,masha). +parent(masha,rustam). +parent(lucefer,rustam). +grandparent(X,Z):-parent(X,Y),parent(Y,Z). +gender(abraam,male). +gender(isaak,male). +gender(petr,male). +gender(rohima,female). +gender(stefan,male). +gender(havriil,male). +gender(olga,female). +gender(masha,female). +gender(lucefer,male). +gender(rustam,male). +brother(X,Y):-parent(Z,X),parent(Z,Y),gender(X,male),gender(Y,female). +predok(X,Y):-parent(X,Y). +predok(X1,XN):-predok(X1,X2),predok(X2,XN). diff --git a/prolog/parents2.pl b/prolog/parents2.pl new file mode 100644 index 0000000..468ca6b --- /dev/null +++ b/prolog/parents2.pl @@ -0,0 +1,24 @@ +parent(abraam,isaak). +parent(abraam,petr). +parent(isaak,havriil). +parent(isaak,olga). +parent(petr,stefan). +parent(rohima,havriil). +parent(rohima,olga). +parent(havriil,masha). +parent(masha,rustam). +parent(lucefer,rustam). +grandparent(X,Z):-parent(X,Y),parent(Y,Z). +gender(abraam,male). +gender(isaak,male). +gender(petr,male). +gender(rohima,female). +gender(stefan,male). +gender(havriil,male). +gender(olga,female). +gender(masha,female). +gender(lucefer,male). +gender(rustam,male). +brother(X,Y):-parent(Z,X),parent(Z,Y),gender(X,male),gender(Y,female). +predok(X,Y):-parent(X,Y). +predok(X1,XN):-predok(X1,X2),predok(X2,XN). diff --git a/prolog/queens.pl b/prolog/queens.pl new file mode 100644 index 0000000..50583a8 --- /dev/null +++ b/prolog/queens.pl @@ -0,0 +1,96 @@ +/*-------------------------------------------------------------------------*/ +/* Benchmark (Finite Domain) */ +/* */ +/* Name : queens.pl */ +/* Title : N-queens problem */ +/* Original Source: P. Van Hentenryck's book */ +/* Adapted by : Daniel Diaz for GNU Prolog */ +/* Date : January 1993 */ +/* */ +/* Put N queens on an NxN chessboard so that there is no couple of queens */ +/* threatening each other. */ +/* */ +/* Solution: */ +/* N=4 [2,4,1,3] */ +/* N=8 [1,5,8,6,3,7,2,4] */ +/* N=16 [1,3,5,2,13,9,14,12,15,6,16,7,4,11,8,10] */ +/*-------------------------------------------------------------------------*/ + + +q:- get_fd_labeling(Lab), write('N ?'), read_integer(N), + statistics(runtime,_), + queens(N,L,Lab), statistics(runtime,[_,Y]), + write(L), nl, + write('time : '), write(Y), nl. + + + + +queens(N,L,Lab):- + fd_set_vector_max(N), + length(L,N), + fd_domain(L,1,N), + safe(L), + lab(Lab,L). + + + + +safe([]). + +safe([X|L]):- + noattack(L,X,1), + safe(L). + + + + +noattack([],_,_). + +/* +% faster than the original PVH's version + +noattack([Y|L],X,I):- + I1 is I+1, + noattack(L,X,I1), + diff(X,Y,I). +*/ + +noattack([Y|L],X,I):- + diff(X,Y,I), + I1 is I+1, + noattack(L,X,I1). + + + +diff(X,Y,I):- + fd_tell(diff(X,Y,I)). + +/* +diff(X,Y,I):- + X#\=Y, + X#\=Y+I, + X+I#\=Y. +*/ + +lab(normal,L):- + fd_labeling(L). + +lab(ff,L):- + fd_labelingff(L). + + + + +get_fd_labeling(Lab):- + argument_counter(C), + get_labeling1(C,Lab). + + +get_labeling1(1,normal). + +get_labeling1(2,Lab):- + argument_value(1,Lab). + + +:- initialization(q). diff --git a/prolog/queens_fd.fd b/prolog/queens_fd.fd new file mode 100644 index 0000000..3b7030a --- /dev/null +++ b/prolog/queens_fd.fd @@ -0,0 +1,6 @@ +diff(fdv X,fdv Y,int I) + +{ + start X in ~{val(Y),val(Y)+I,val(Y)-I} + start Y in ~{val(X),val(X)+I,val(X)-I} +} diff --git a/python/akk.py b/python/akk.py new file mode 100644 index 0000000..fad4349 --- /dev/null +++ b/python/akk.py @@ -0,0 +1,6 @@ +def akk(m,n): + if m==0: return n+1 + if n==0: return akk(m-1,1) + return akk(m-1,akk(m,n-1)) + +print akk(3,8) diff --git a/ruby/hello b/ruby/hello new file mode 100644 index 0000000..dcc6880 --- /dev/null +++ b/ruby/hello @@ -0,0 +1,9 @@ +#!/usr/bin/ruby + +str = "Привет" + +def str.bye + "Пока!" +end + +puts str.bye