├── signals ├── Makefile └── p_sigaction.c ├── README.md ├── processes ├── p_print_argv_env.c └── p_execve.c └── LICENSE /signals/Makefile: -------------------------------------------------------------------------------- 1 | p_sigaction: p_sigaction.c 2 | gcc -o $@ $^ 3 | 4 | clean: 5 | rm -f p_sigaction 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Список курсов 2 | 3 | ## [Безопасность операционных систем](https://github.com/efanov/mephi/wiki/%D0%91%D0%B5%D0%B7%D0%BE%D0%BF%D0%B0%D1%81%D0%BD%D0%BE%D1%81%D1%82%D1%8C-%D0%BE%D0%BF%D0%B5%D1%80%D0%B0%D1%86%D0%B8%D0%BE%D0%BD%D0%BD%D1%8B%D1%85-%D1%81%D0%B8%D1%81%D1%82%D0%B5%D0%BC) 4 | -------------------------------------------------------------------------------- /processes/p_print_argv_env.c: -------------------------------------------------------------------------------- 1 | /* p_print_argv_env.c */ 2 | 3 | #include 4 | #include 5 | 6 | extern char **environ; 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | int j; 11 | char **ep; 12 | 13 | /* Display argument list */ 14 | 15 | for (j = 0; j < argc; j++) 16 | printf("argv[%d] = %s\n", j, argv[j]); 17 | 18 | /* Display environment list */ 19 | 20 | for (ep = environ; *ep != NULL; ep++) 21 | printf("environ: %s\n", *ep); 22 | 23 | exit(EXIT_SUCCESS); 24 | } 25 | -------------------------------------------------------------------------------- /processes/p_execve.c: -------------------------------------------------------------------------------- 1 | /* p_execve.c */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int 9 | main(int argc, char *argv[]) 10 | { 11 | char *newargv[] = { NULL, "Russia", "Moscow", NULL }; 12 | char *newenviron[] = { "University=MEPhI", NULL }; 13 | 14 | if (argc != 2) { 15 | fprintf(stderr, "Usage: %s \n", argv[0]); 16 | exit(EXIT_FAILURE); 17 | } 18 | 19 | newargv[0] = strrchr(argv[1], '/'); /* Get basename from argv[1] */ 20 | if (newargv[0] != NULL) 21 | newargv[0]++; 22 | else 23 | newargv[0] = argv[1]; 24 | 25 | execve(argv[1], newargv, newenviron); 26 | perror("execve"); /* execve() returns only on error */ 27 | exit(EXIT_FAILURE); 28 | } 29 | -------------------------------------------------------------------------------- /signals/p_sigaction.c: -------------------------------------------------------------------------------- 1 | /* p_sigaction.c */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | sig_atomic_t sig_received = 0; 11 | 12 | void handler(int sig) 13 | { 14 | sig_received = sig; 15 | } 16 | 17 | int main(int argc, char *argv[]) 18 | { 19 | struct sigaction act; 20 | sigemptyset(&act.sa_mask); 21 | act.sa_flags = 0; 22 | act.sa_handler = &handler; 23 | 24 | printf("%s: PID is %ld\n", argv[0], (long) getpid()); 25 | 26 | if (sigaction(SIGINT, &act, NULL) == -1) { 27 | perror("sigaction"); 28 | exit(EXIT_FAILURE); 29 | } 30 | 31 | while (1) { 32 | if (sig_received) { 33 | printf("Received signal %d (%s)\n", sig_received, strsignal(sig_received)); 34 | sig_received = 0; 35 | } 36 | } 37 | 38 | exit(EXIT_SUCCESS); 39 | } 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Dmitry Efanov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | --------------------------------------------------------------------------------