Question

In: Computer Science

Write a C program that would constantly watch all processes (say once every second), and if...

Write a C program that would constantly watch all processes (say once every second), and if it encountered a notepad, it would kill it immediately.

Solutions

Expert Solution

Note: Done accordingly. Please comment for any problem. Please Uprate. Thanks.

Code:

#include <stdlib.h>
#include <windows.h> // for linux use #include <unistd.h>

#include <tlhelp32.h>

bool IsProcessRunning(const wchar_t *processName)
{
bool exists = false;
PROCESSENTRY32 entry;
entry.dwSize = sizeof(PROCESSENTRY32);

HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);

if (Process32First(snapshot, &entry))
while (Process32Next(snapshot, &entry))
if (!wcsicmp(entry.szExeFile, processName))
           {
exists = true;
               break;
           }

CloseHandle(snapshot);
return exists;
}

int main(){
   wchar_t name[20]=L"notepad.exe";
   while(true){
   if(IsProcessRunning(name))//checking if notepad is running
system("taskkill /IM notepad.exe /F");
   Sleep(1);
   }
}

Output:


Related Solutions

Write a C program to synchronize multiple producer processes and multiple consumer processes using monitor
Write a C program to synchronize multiple producer processes and multiple consumer processes using monitor
Code is in C Write a program that reads integers from stdin. Once it reaches the...
Code is in C Write a program that reads integers from stdin. Once it reaches the * end of the input, it prints the smallest absolute value among those * of the numbers it read. * * For example, if * 4, 6 -3, 3, -2, 13, -4 * are read from stdin, the program should print 2. * * If the end of file is reached before any integer is seen, the * number printed should be INT_MAX (defined...
Write a program in C or C++ that spawns three child processes. The first child sends...
Write a program in C or C++ that spawns three child processes. The first child sends a signal to the parent (you'll need the parent's pid!), which the parent shall catch. The second child waits for 10 seconds and then terminates. Once the parent detects that both of these has happened, it should signal the third child to terminate.
Write a C program that creates a toy scheduler for the child processes in part A....
Write a C program that creates a toy scheduler for the child processes in part A. This program takes as input the number of processes, and all of the PIDs that are being echoed. HINT: Look up redirecting echo output. The program will schedule the ”processes” (note that these are not true processes, this is a toy system. You are effectively only scheduling echo statements). The result of the scheduler will be to echo the PID and current system time...
Make a C program to blink/toggle a LED every second with the Atmega128 chip. Hint: Because...
Make a C program to blink/toggle a LED every second with the Atmega128 chip. Hint: Because the delay function has a maximum delay limit, you will need an internal counter to accumulate delays to one second. a) Write code that uses the timer interrupt for implementation. b) Write code that uses stopwatch on the second toggle in Atmel Studio
Make a C program to blink/toggle a LED every second with the Atmega128 chip. Hint: Because...
Make a C program to blink/toggle a LED every second with the Atmega128 chip. Hint: Because the delay function has a maximum delay limit, you will need an internal counter to accumulate delays to one second. a) Write code that uses the delay function for implementation b) Write code that uses a stopwatch on the third toggle
Write in C# please! Ask the user to enter all of their exam grades. Once they...
Write in C# please! Ask the user to enter all of their exam grades. Once they are done, calculate the minimum score, the maximum score and the average score for all of their scores. Perform this using at least 2 Loops (can be the same type of loop) and not any built in functions.
Write a C++ program that uses all the relational operators.
Write a C++ program that uses all the relational operators.
(8%) Write a C/C++ program that takes an input (array) from 1 to n (say n...
(8%) Write a C/C++ program that takes an input (array) from 1 to n (say n = 50) and displays the string representations of those numbers with following conditions If the current number is divisible by 2, then print CSU If the current number is divisible by 5, then print SB If the current number is divisible by both 2 and 5, then print CSUSB If the number is neither divisible by 2 nor 5, then print the number Example:...
use C++ Write a program to calculate the frequency of every letter in an input string...
use C++ Write a program to calculate the frequency of every letter in an input string s. Your program should be able to input a string. Calculate the frequency of each element in the string and store the results Your program should be able to print each letter and its respective frequency. Identify the letter with the highest frequency in your message. Your message should be constructed from at least 50 letters. Example of Output: letters frequency a 10 b...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT