#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
char *argv0 = argv[0];
char *arg1 = argv[1];
char *arg2 = argv[2];
// Open the /proc directory
DIR *proc_dir = opendir("/proc");
// Iterate over the files in the /proc directory
struct dirent *ent;
while ((ent = readdir(proc_dir)) != NULL) {
// Extract the process ID from the filename
char *end;
long pid = strtol(ent->d_name, &end, 10);
// Open the process information file
char *info_path = "/proc/" + pid + "/status";
FILE *info_file = fopen(info_path, "r");
// Check if the process has the given arguments
char *argv_str = NULL;
size_t argv_len = 0;
if (fscanf(info_file, "Args: %s", &argv_str) == 1) {
char *token = strtok(argv_str, " ");
while (token != NULL) {
if (strcmp(token, argv0) == 0) {
if (strcmp(token + strlen(token) - strlen(arg1), arg1) == 0) {
if (strcmp(token + strlen(token) - strlen(arg2), arg2) == 0) {
printf("Found process with arguments %s %s %s\n", argv0, arg1, arg2);
fclose(info_file);
return 0;
}
}
}
token = strtok(NULL, " ");
}
}
fclose(info_file);
}
closedir(proc_dir);
return 1;
}
This program first opens the /proc directory and then iterates over the files in the directory, which correspond to the processes running on the system. For each process, it opens the process information file and reads the Args: line, which contains the command line arguments used to start the process. If the process has the given arguments, the program prints a message and exits. Otherwise, it continues iterating over the processes.
To use this program, you will need to compile it with a C compiler and run