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...
Write a C program to create a series of processes, as shown below in the diagram....
Write a C program to create a series of processes, as shown below in the diagram. P |------ ---- > c1 |------------>c2                              |------- ------>c3 ---------->c4                             In other words, the parent process p creates process c1, c1 creates c2 and c3, and c3 creates c4. A sample run of the program shows Your program should output something similar to what is shown above. You could optionally use wait/waitpid/sleep/exit in your program. Comment your code to show where you created...
Write a C program to create a series of processes, as shown below in the diagram....
Write a C program to create a series of processes, as shown below in the diagram. P - ------------------ > c1 ------------>c3    |                                          |    |------------------> c2 |----- >c4 In other words, the parent process p creates processes c1 and c2, c1 creates c3 and c4.
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT