How to run this program?

I can compile this program, which was provided to me, but what should I develop. I have some questions:

#include <sys/types.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #define TIMEOUT (20) int main(int argc, char *argv[]) { pid_t pid; if(argc > 1 && strncmp(argv[1], "-help", strlen(argv[1])) == 0) { fprintf(stderr, "Usage: RunSafe Prog [CommandLineArgs]\n\nRunSafe takes as arguments:\nthe program to be run (Prog) and its command line arguments (CommandLineArgs) (if any)\n\nRunSafe will execute Prog with its command line arguments and\nterminate it and any remaining childprocesses after %d seconds\n", TIMEOUT); exit(0); } if((pid = fork()) == 0) /* Fork off child */ { execvp(argv[1], argv+1); fprintf(stderr,"RunSafe failed to execute: %s\n",argv[1]); perror("Reason"); kill(getppid(),SIGKILL); /* kill waiting parent */ exit(errno); /* execvp failed, no child - exit immediately */ } else if(pid != -1) { sleep(TIMEOUT); if(kill(0,0) == 0) /* are there processes left? */ { fprintf(stderr,"\nRunSafe: Attempting to kill remaining (child) processes\n"); kill(0, SIGKILL); /* send SIGKILL to all child processes */ } } else { fprintf(stderr,"RunSafe failed to fork off child process\n"); perror("Reason"); } } 

What does my compilation warning mean?

 $ gcc -o RunSafe RunSafe.c -lm RunSafe.c: In function 'main': RunSafe.c:30:44: warning: incompatible implicit declaration of built-in function 'strlen' [enabled by default] 

Why can't I execute the file?

 $ file RunSafe RunSafe: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0x0a128c8d71e16bfde4dbc316bdc329e4860a195f, not stripped ubuntu@ubuntu :/media/Lexar$ sudo chmod 777 RunSafe ubuntu@ubuntu :/media/Lexar$ ./RunSafe bash: ./RunSafe: Permission denied ubuntu@ubuntu :/media/Lexar$ sudo ./RunSafe sudo: ./RunSafe: command not found 
+4
source share
2 answers

First, you need #include <string.h> to get rid of this warning.

Secondly, the OS probably prevents the execution of programs in the /media/Lexar file system, regardless of what their resolution bits are. If you type mount , you will probably see the noexec option for /media/Lexar .

+2
source

warning: incompatible implicit declaration of the built-in function 'strlen [enabled by default]

You need to include #include<string.h> because strlen() declared in it.

Try running exe at a different location on your file system, rather than on the mounted partition, as the error indicates for some reason that you do not have permissions on this mounted partition.

+1
source

Source: https://habr.com/ru/post/1416285/


All Articles