我有一个无法杀死的进程kill -9 <pid>。在这种情况下有什么问题,特别是因为我是该流程的所有者。我认为没有什么可以逃避这个kill选择。
我想要与这个问题完全相反的问题。我想知道如何创建一个在被终止后继续重新启动的进程。有人能给我一个实施示例吗?
例如,假设我有一个简单的过程,它将时间戳和递增计数器连续记录到日志文件中,如下所示:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#define FILE_PATH "/home/lincoln/date.log"
int main() {
time_t current_time;
struct tm *time_info;
int counter = 0;
while (1) {
FILE *file = fopen(FILE_PATH, "a");
if (file == NULL){
perror("Failed to open the file");
return 1;
}
// Get the current timestamp
time(¤t_time);
time_info = localtime(¤t_time);
// Format the timestamp
char timestamp[25];
strftime(timestamp, sizeof(timestamp), "%Y-%m-%d %H:%M:%S", time_info);
// Write timestamp and counter to the file
fprintf(file, "%s | …Run Code Online (Sandbox Code Playgroud)