3
嗨我必須爲系統調用編寫2個函數來管理操作系統中任務的執行。我無法找到暫停/重新啓動進程的方法。我已經找到了信號的名單,我知道殺功能,這裏是我的代碼:如何暫停/重啓C(linux)中的進程
#include <stdlib.h>
#include <signal.h>
typedef struct File
{
int pid;
struct File *pids;
} *file;
file file1 = NULL;
//this fonction is to suspend a process using its pid number
int V(int pid_num)
{
//does the kill fonction just kill the process or will it take into account the signal argument?
kill(pid_num, SIGSTOP);
file1 = ajouter(file1, pid_num);
return 0;
}
//this is to restart the process
int C()
{
if (file1 != NULL)
{
//I know the kill fonction is not the right one but I just don't know any other to take as argument the pid of a process to restart it
kill(file1->pid, SIGCONT);
}
return 0;
}
//this fontion adds pid number to our structure
file ajouter(file file_n, int pid)
{
file nouveau = malloc(sizeof(file));
nouveau->pid = pid;
nouveau->pids = file_n;
return nouveau;
}
備註:此代碼是不應該真正發揮作用,它只是一點點模擬 感謝很多提前
爲什麼你使用全局'file1'並將它作爲'ajouter'的參數?這是無用的,全球選擇或不選擇,但不混合。 此外,更喜歡'next'而不是'pids',因爲這是一個鏈式列表 – Eregrith 2012-02-15 16:25:26