2つのファイルを比較し、等しいかどうかを返すプログラムを作成しようとしています。 fork
、dup
、dup2
、open
、write
、exec
とread
:bash:./comp.out:許可が拒否されました
私だけの機能を使用することができます。
私はLinuxのgccの上でプログラムをコンパイルすると、それが返されます。
のbash:./comp.out:許可コード
を拒否:
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int CheckSimilar(char *path1, char *path2);
int main(int argc, char **argv) {
int returnValue = CheckSimilar(argv[1], argv[2]);
switch (returnValue){
case 1:
write(1, "1\n", 3);
break;
case 2:
write(1, "2\n", 3);
break;
case 3:
write(1, "3\n", 3);
break;
default:
break;
}
return 0;
}
/*
* This function checks if the files are similar or similar by case sensitive
* it gets 2 files, and returns: 3 if identical, 2 if identical but only if not
* case sensitive or 1 else.
*/
どのように権限を変更しますか?
[email protected] ~/workspace/targ1OS $ gcc -c ec11.c -o comp.out
[email protected] ~/workspace/targ1OS $ ls
comp.out Debug ec11.c
[email protected] ~/workspace/targ1OS $ ./comp.out /home/shay/Downloads/input.txt /home/shay/Downloads/input.txt
bash: ./comp.out: Permission denied
[email protected] ~/workspace/targ1OS $ comp.out /home/shay/Downloads/input.txt /home/shay/Downloads/input.txt
comp.out: command not found
[email protected] ~/workspace/targ1OS $ ./comp.out /home/shay/Downloads/input.txt /home/shay/Downloads/input.txt
bash: ./comp.out: Permission denied
[email protected] ~/workspace/targ1OS $ ^C
[email protected] ~/workspace/targ1OS $ ls -al ./comp.out
-rw-r--r-- 1 shay shay 2640 Mar 30 10:05 ./comp.out
[email protected] ~/workspace/targ1OS $ chmod ogu+x ./comp.out
[email protected] ~/workspace/targ1OS $ ./comp.out /home/shay/Downloads/input.txt /home/shay/Downloads/input.txt
bash: ./comp.out: cannot execute binary file: Exec format error
[email protected] ~/workspace/targ1OS $ gcc -c ec11.c -o comp.out
[email protected] ~/workspace/targ1OS $ ./comp.out /home/shay/Downloads/input.txt /home/shay/Downloads/input.txt
bash: ./comp.out: Permission denied
[email protected] ~/workspace/targ1OS $ chmod ogu+x ./comp.out
[email protected] ~/workspace/targ1OS $ ./comp.out /home/shay/Downloads/input.txt /home/shay/Downloads/input.txt
bash: ./comp.out: cannot execute binary file: Exec format error
[email protected] ~/workspace/targ1OS $ comp.out /home/shay/Downloads/input.txt /home/shay/Downloads/input.txt
comp.out: command not found
'sudo。/ comp.out'を実行しますか? –
しかし、私はターミナルでコマンドを使用することはできません。 –
どういう意味ですか?何らかの理由でそれらを使用することは許されていませんか? –