From a4e444f43a856d2ab12a23570687b8a0b5bce7dc Mon Sep 17 00:00:00 2001 From: MAO Dongyang Date: Wed, 15 Mar 2023 08:40:42 +0100 Subject: [PATCH 1/3] create ps by fork() --- file_operate/create_ps/a.out | Bin 0 -> 49560 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100755 file_operate/create_ps/a.out diff --git a/file_operate/create_ps/a.out b/file_operate/create_ps/a.out new file mode 100755 index 0000000000000000000000000000000000000000..83a05690b7839199b849a1adaca990a2c09b3946 GIT binary patch literal 49560 zcmeI*OK4nG7{Ku}d9>3S(}@L%+Tt}eK1yx06sdx7VmlPfExhLoR z?w#%~{r<1t|JiR$s?!+LAvGg)vfG#&#*xUFhop{4wf4%$XzumgwaePuT2ig)u9>d$ zqfE4RA~!kFIwib6+uCR1T()A8sxzz&-0OixQE6XqYFG{!<*mRkt=G5AH zurOWU>S|x_k9fWQct(;ZH>BhB_Qf61dba46YOXJR?dzpqj`nvZp0ByOZzy}Dh2CRW~*V|`aEvO>*+JsqIvro(MWXF=Xz7B zwdY1AM(o+km&T)~n~lzyJjeD{-#4xLtn{6;cCOm=Sod5nEpx+?jqZ;#qyEj$S@*Re zHQHA)OWLKjeMugcY}6$CO3rL;DR1kG<>_k4)&hUe^_=MTaD81PDe~J2-`^y+wvZ3< zNw#x;&Qi3$5)Xqh_Qd0cw+y-Uhda(-P$|Gj7~`gir*Iu^YXPs%Y;+k27yj4##$w|w%Ild>;w zI=cG_X>|P$)+3*%<6ONc2q1s}0tg_000IagfB*srAbT9@gjwjpTDtv-zz=uJ2cU$E!HARe%05bKc39ouKGC zGexgdaB6;a#;w;+IOWA8cD#b))t$k@!R^Vlyzf?mWX2w|qiYWgFJUE3Nu?lw00IagfB*srAb&q4v zO9fjG7N+gAS1Gu@x$2uWQ#<>@+{Wr&FXP!3BwX)5bVUvV_FC#GzD1u2KGA zm>V-S9OXx%ew`YY0l7-Dl^<`*PqpPQwB? Date: Wed, 15 Mar 2023 10:23:06 +0100 Subject: [PATCH 2/3] create c_pprocess --- file_operate/create_ps/main.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 file_operate/create_ps/main.c diff --git a/file_operate/create_ps/main.c b/file_operate/create_ps/main.c new file mode 100644 index 0000000..70a32a0 --- /dev/null +++ b/file_operate/create_ps/main.c @@ -0,0 +1,22 @@ +#include +#include +#include +#include + +int main() { + pid_t fpid; + + fpid = fork(); + // create child process + if (fpid < 0) { + printf("error in fork!"); + } else if (fpid == 0) { + printf("I am the child process, my process id is %d\n", getpid()); + sleep(10); + } else { + printf("I am the parent process, my process id is %d\n", getpid()); + wait(NULL); + // exit(0); + } + return 0; +} From 28aa63db4d1608452024fa594ce99ec3d8f9d875 Mon Sep 17 00:00:00 2001 From: MAO Dongyang Date: Wed, 15 Mar 2023 10:24:26 +0100 Subject: [PATCH 3/3] Liste fini --- TP3/List/Liste.c | 140 +++++++++++++++++++++++++++++++++++++++++++++++ TP3/List/Liste.h | 22 ++++++++ TP3/List/main.c | 64 ++++++++++++++++++++++ 3 files changed, 226 insertions(+) create mode 100644 TP3/List/Liste.c create mode 100644 TP3/List/Liste.h create mode 100644 TP3/List/main.c diff --git a/TP3/List/Liste.c b/TP3/List/Liste.c new file mode 100644 index 0000000..5cee04f --- /dev/null +++ b/TP3/List/Liste.c @@ -0,0 +1,140 @@ +#include +#include +#include "Liste.h" + +struct SList +{ + SCell *first; + SCell *last; +}; + +struct SCell +{ + int data; + SCell *next; + SCell *prev; +}; + +SList *CreateList() +{ + SList *list = (SList *)malloc(sizeof(SList)); + list->first = NULL; + list->last = NULL; + return list; +} + +void DeleteList(SList *list) +{ + SCell *cell = GetFirstElement(list); + while (cell != NULL) + { + SCell *next = GetNextElement(cell); + DeleteCell(list, cell); + cell = next; + } + free(list); +} + +SCell *AddElementBegin(SList *list, int data) +{ + SCell *cell = (SCell *)malloc(sizeof(SCell)); + cell->data = data; + cell->next = list->first; + cell->prev = NULL; + if (list->first != NULL) + { + list->first->prev = cell; + } + list->first = cell; + if (list->last == NULL) + { + list->last = cell; + } + return cell; +} + +SCell *AddElementEnd(SList *list, int data) +{ + SCell *cell = (SCell *)malloc(sizeof(SCell)); + cell->data = data; + cell->next = NULL; + cell->prev = list->last; + if (list->last != NULL) + { + list->last->next = cell; + } + list->last = cell; + if (list->first == NULL) + { + list->first = cell; + } + return cell; +} + +SCell *AddElementAfter(SList *list, SCell *cell, int data) +{ + if (cell == NULL) + { + return AddElementBegin(list, data); + } + else if (cell == list->last) + { + return AddElementEnd(list, data); + } + else + { + SCell *newCell = (SCell *)malloc(sizeof(SCell)); + newCell->data = data; + newCell->next = cell->next; + newCell->prev = cell; + cell->next->prev = newCell; + cell->next = newCell; + return newCell; + } +} + +void DeleteCell(SList *list, SCell *cell) +{ + if (cell == list->first) + { + list->first = cell->next; + } + if (cell == list->last) + { + list->last = cell->prev; + } + if (cell->prev != NULL) + { + cell->prev->next = cell->next; + } + if (cell->next != NULL) + { + cell->next->prev = cell->prev; + } + free(cell); +} + +SCell *GetFirstElement(SList *list) +{ + return list->first; +} + +SCell *GetLastElement(SList *list) +{ + return list->last; +} + +SCell *GetNextElement(SCell *cell) +{ + return cell->next; +} + +SCell *GetPrevElement(SCell *cell) +{ + return cell->prev; +} + +int GetData(SCell *cell) +{ + return cell->data; +} \ No newline at end of file diff --git a/TP3/List/Liste.h b/TP3/List/Liste.h new file mode 100644 index 0000000..6b7da63 --- /dev/null +++ b/TP3/List/Liste.h @@ -0,0 +1,22 @@ +#ifndef _LISTE_H +#define _LISTE_H + +typedef int Data; +typedef struct SCell SCell; +typedef struct SList SList; + +SList *CreateList(); +void DeleteList(SList *list); + +SCell *AddElementBegin(SList *list, Data elem); +SCell *AddElementEnd(SList *list, Data elem); +SCell *AddElementAfter(SList *list, SCell *cell, Data elem); +void DeleteCell(SList *list, SCell *cell); + +SCell *GetFirstElement(SList *list); +SCell *GetLastElement(SList *list); +SCell *GetPrevElement(SCell *cell); +SCell *GetNextElement(SCell *cell); +Data GetData(SCell *cell); + +#endif diff --git a/TP3/List/main.c b/TP3/List/main.c new file mode 100644 index 0000000..7a52834 --- /dev/null +++ b/TP3/List/main.c @@ -0,0 +1,64 @@ +#include +#include +#include "Liste.h" + +void PrintList(SList *list); + +int main() +{ + SList *list; + SCell *cell; + + list = CreateList(); + + printf("Add 5, 3, 1\n"); + AddElementBegin(list, 5); + cell = AddElementBegin(list, 3); + AddElementBegin(list, 1); + PrintList(list); + printf("\n"); + + printf("Add 6, 8\n"); + AddElementEnd(list, 6); + AddElementEnd(list, 8); + PrintList(list); + printf("\n"); + + printf("Add 4\n"); + AddElementAfter(list, cell, 4); + PrintList(list); + printf("\n"); + + printf("Add 2\n"); + AddElementAfter(list, GetFirstElement(list), 2); + PrintList(list); + printf("\n"); + + printf("Delete 3\n"); + DeleteCell(list, cell); + PrintList(list); + printf("\n"); + + printf("Add 7\n"); + AddElementAfter(list, GetPrevElement(GetLastElement(list)), 7); + PrintList(list); + printf("\n"); + + DeleteList(list); + + return 0; +} + +void PrintList(SList *list) +{ + if (list) + { + SCell *cell = GetFirstElement(list); + while (cell != NULL) + { + printf("[%d] -> ", GetData(cell)); + cell = GetNextElement(cell); + } + printf("NULL\n"); + } +}