bạn có thể dùng fork hoặc pthread để tạo ra tiến trình mới
Em có một đề tài nội dung như sau:
Viết chương trình tạo ra một quá trình con. Quá trình cha sẽ nhận chuỗi số
nguyên từ bàn phím do người dùng nhập và ghi vào file tên input. Quá trình con sẽ
đọc dữ liệu từ file này, sắp xếp chúng theo thứ tự tăng dần và ghi vào một file khác
tên là sorted.
Em đã biết lập trình C căn bản
Ai có tài liệu về cái này share cho em để nghiên cứu dc ko
Hoặc ai có bài tập tương tự thì share code để em tham khảo dc ko
Thank các pro nhiều
bạn có thể dùng fork hoặc pthread để tạo ra tiến trình mới
RISC better than CISC
phamthechung0@gmail.com
bạn hướng dẫn rõ tí được không
Có ebook hoặc code tương tự thì bạn share cho mình được không
thanks
Đây là pthread: http://www.yolinux.com/TUTORIALS/Lin...ixThreads.html
Đây là process: http://www.yolinux.com/TUTORIALS/ForkExecProcesses.html
Lần sau với mấy thứ này tự search trước nhé.
bất cứ cái gì mới hãy hỏi Mr Google trước đi bạn, bí quá thì mới post lên đây, làm coder ko chủ động ko ăn đc đâu (code là 1 trong những công việc phải nhồi sọ nhiều nhất, có hàng tấn tấn những thứ cần phải nghiên cứu)
day la laptrinh c tren linux nha ban
#include<stdlib.h>
#include<stddef.h>
#include<stdio.h>
#include<string.h>
#include<sys/types.h>
#include<sys/wait.h>
int main(){
int n;int pid;
int a[100];
printf("moi ban nhap so luong phan tu ");
scanf("%d",&n);
nhapmang(n,a);
printf("--------------------------------");
printf("\n day la qua trinh cha \n ");
printf("-------------------------------");
/*
n=2;
a[0]=1;a[1]=4;a[2]=7;
*/
ghifileinput(n,a);
pid=fork();
if(pid==0){
printf("--------------------------------");
printf("\n day la process con \n");
printf("--------------------------------");
docfile(n,a);
selection(n,a);
ghifilesort(n,a);
printf("--------------------------------\n");
}
return 0;
}
//ghi vao file txt
int ghifileinput(int n,int a[])
{
FILE *fl;
int i;
fl=fopen("input.txt","w");
if(!fl)
return 1;
for(i=0;i<=n;i++){
fprintf(fl,"%d\n",a[i]);
}
fclose(fl);
printf("\n da ghi vao file input.txt\n");
return 1;
}
//doc file len mang
int docfile(int n,int a[])
{
FILE *fd;char line[100];int i=0;
int atoi(const char* str);
fd=fopen("input.txt","r");
if(!fd)
return 1;
while(fgets(line,sizeof(line),fd)!=NULL)
{
a[i]=atoi(line);
i++;
}
fclose(fd);
return 0;
}
//sap xep
int selection(int n,int a[])
{
int i,j,min,temp;
for(i=0;i<n-1;i++)
{ min=j;
for(j=i+1;j<=n;j++)
if(a[j]<a[min])
min=j;
temp=a[i];
a[i]=a[min];
a[min]=temp;
printf("\nda sap xep");
return 0;
}
}
int inra(int n,int a[])
{int t;
for(t=0;t<=n;t++)
printf("%d",a[t]);
printf("\n");
return 0;
}
//ghi vao file sorted
int ghifilesort(int n,int a[])
{
FILE *fl;
int i;
fl=fopen("sorted.txt","w");
if(!fl)
return 1;
for(i=0;i<=n;i++)
fprintf(fl,"%d \n",a[i]);
fclose(fl);
printf("\n da in vao file sorted.txt\n");
return 0;
}
//nhap mang
int nhapmang(int n,int a[])
{int i;
for(i=0;i<=n;i++)
{
printf("moi ban nhap phan tu thu a[%d] ",i);
scanf("%d",&a[i]);
}
return 1;
}