相关疑难解决方法(0)

如果“kill -9”不起作用怎么办?

我有一个无法杀死的进程kill -9 <pid>。在这种情况下有什么问题,特别是因为我是该流程的所有者。我认为没有什么可以逃避这个kill选择。

process kill

556
推荐指数
13
解决办法
65万
查看次数

如何编写一个每次被杀死后都会重新启动的进程

我想要与这个问题完全相反的问题。我想知道如何创建一个在被终止后继续重新启动的进程。有人能给我一个实施示例吗?

例如,假设我有一个简单的过程,它将时间戳和递增计数器连续记录到日志文件中,如下所示:

#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(&current_time);
        time_info = localtime(&current_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)

linux shell process background-process

0
推荐指数
1
解决办法
736
查看次数

标签 统计

process ×2

background-process ×1

kill ×1

linux ×1

shell ×1