#include<stdio.h>
#include <signal.h>
void signalHandler(int);
int main()
{
struct sigaction sa;
sa.sa_flags = 0;
// Setup the signal handler
sa.sa_handler = signalHandler;
// Block every signal during the handler
sigfillset(&sa.sa_mask);
if (sigaction(SIGINT, &sa, NULL) == -1) {
printf("Error: cannot handle SIGINT\n");
}
while(1)
{
printf("Start to ping google.com");
system("ping www.google.com -c 1");
printf("Stop to ping google.com\n");
sleep(1);
}
}
void signalHandler(int signal)
{
printf("signalHandler: signal = %d\n", signal);
}
Другой вариант:
WARNING: it is possible that due to funny characters in directory names it is possible that unintended files might be deleted.
find ./ -type f \( -name fileA -o -name fileB \) -print | xargs rm -f
Или, если возможно, поймать эти файлы с забавными персонажами:
NOTE: On some systems -print0 and -0 options are not available. But this would be the preferred and safer method)
find ./ -type f \( -name fileA -o -name fileB \) -print0 | xargs -0 rm -f
-o
также применяется к действию, поэтому вам нужно сгруппировать вещи:
find ./ -type f \( -name fileA -o -name fileB \) -exec rm {} \;
Кстати, ваша реализация find
может также поддерживать -delete
:
find ./ -type f \( -name fileA -o -name fileB \) -delete