Chào các bạn! Vì nhiều lý do từ nay Truyen2U chính thức đổi tên là Truyen247.Pro. Mong các bạn tiếp tục ủng hộ truy cập tên miền mới này nhé! Mãi yêu... ♥

phầnc

Bài 36

#include "stdio.h"

main(){

      int pid;

      pid=fork();

      if(pid!=0)

            printf("

tien trinh cha ke thuc voi PID=%d,PPID=%d",getpid(),getppid());

      else sleep(5);

      printf("

tien trinh con tro thanh tien trinh bo vo voi PID=%d,PPID=%d

",getpid(),getppid());

}

Bài 37

#include "stdio.h"

main(){

      int pid;

      pid=fork();

      if(pid!=0)

            while(1) sleep(1000);

      else exit(42);

}

BÀI 38

#include "stdio.h"

#include "sys/file.h"

#include "string.h"

int docmatran(int[10][10]);

int convert(char);

void luumatran(int[10][10],int);

void xuongdong(int);

void writeC(int,int);

main(){

            char s[100];

            int l1=0,l2=0,mtA[10][10],mtB[10][10],mtC[10][10],i,j,k;

            printf("nhap file ma tran A:

");

            l1=docmatran(mtA);

            printf("nhap file ma tran B:

");

            l2=docmatran(mtB);

            for(i=1;i<=l1;i++)

                        for(j=1;j<=l2;j++){

                        mtC[i][j]=0;

                                    for(k=1;k<=l1;k++){

                                       mtC[i][j]=mtC[i][j]+mtA[i][k]*mtB[k][j];              

                                    }

            }

            printf("

ma tran tich A  la :

");

            for(i=1;i<=l1;i++){

                        for(j=1;j<=l1;j++)

                                    printf("%d ",mtA[i][j]);

                        printf("

");

}

            printf("

ma tran tich B  la :

");

            for(i=1;i<=l1;i++){

                        for(j=1;j<=l1;j++)

                                    printf("%d ",mtB[i][j]);

                        printf("

");

}

            printf("

ma tran tich C  la :

");

            for(i=1;i<=l1;i++){

                        for(j=1;j<=l1;j++)

                                    printf("%d ",mtC[i][j]);

                        printf("

");

            }

            luumatran(mtC,l1);

}

int docmatran(int matran[10][10])

{

  int fd,k=1,sg2=1,d[10][10],j=1,s1,s2;

  char i[10],s[100];

            printf("nhap vao file ma tran:");

            fflush(stdin);

            gets(s);

            fd=open(s,O_RDONLY);

            while (sg2!=0){

                        sg2=read(fd,i,1);

                        if(sg2!=0){

                                    d[k][j]=0;

                                    while(((int)i[0] != 32)&&((int)i[0] != 10))     

                                    {         

                                                d[k][j]=d[k][j]*10+convert(i[0]);

                                                sg2=read(fd,i,1);

                                                if((int)i[0]==32) j=j+1;

                                    }

                                    if(((int)i[0] == 10)){

                                                            k=k+1;

                                                            j=1;

                                    }

                        }

            }

            k=k-1;

            for(s1=1;s1<=k;s1++)

                        for(s2=1;s2<=k;s2++)

                                    matran[s1][s2]=d[s1][s2];

            return k;

     close(fd);

}

int convert(char c){

            return (int)c-48;

}

void luumatran(int mt[10][10],int k){

            char s[10];

            int fd,i,j;

            printf("nhap file luu ma tran:");

            fflush(stdin);

            gets(s);

            fd=open(s,O_WRONLY);

            for(i=1;i<=k;i++){

                        for(j=1;j<=k;j++)

                                    writeC(mt[i][j],fd);

                        xuongdong(fd);

            }

            close(fd);

}

void xuongdong(int fd){

            char s[10];

            s[0]=10;

            int wr= write(fd,s,1);

}

void writeC(int a,int fd){

            int k,i,of,wr;

            char so[10],s[10];

            k=0;

            while(a>0){

                        so[k]=a%10+48;

                        k=k+1;

                        a=a/10;

                        }

            for(i=0;i<=k-1;i++)

                        s[i]=so[k-i-1];

            wr=write(fd,s,k);

            s[0]=' ';

            wr=write(fd,s,1);

            if(wr!=-1)printf("

write sucess !

");

                        else printf("

write error !

");

}

BÀI 39

#include "stdio.h"

#include "sys/types.h"

#include "fcntl.h"

#include "string.h"

#include "sys/file.h"

int convert(char);

main(){

  int fd,sg,k=1,sg2=1,d[10][10],j=1,s1,s2,dem=0;

  char i[10],s[100];

      printf("nhap vao file ma tran:");

      fflush(stdin);

      gets(s);

      printf("

nhap gia tri k ma ban muon tim trong ma tran:%d",&sg);

      fd=open(s,O_RDONLY);

      while (sg2!=0){

            sg2=read(fd,i,1);

            if(sg2!=0){

                  d[k][j]=0;

                  while(((int)i[0] != 32)&&((int)i[0] != 10))    

                  {    

                        d[k][j]=d[k][j]*10+convert(i[0]);

                        sg2=read(fd,i,1);

                        if((int)i[0]==32) j=j+1;

                  }

                  if(((int)i[0] == 10)){

                              k=k+1;

                              j=1;

                  }

            }

      }

      k=k-1;

      for(s1=1;s1<=k;s1++){

            for(s2=1;s2<=k;s2++){

                  printf("%d ",d[s1][s2]);

                  if (sg==d[s1][s2]) dem=dem+1;

                  }

            printf("

");

      }

      if(dem != 0)printf("

gia tri %d xuat hien trong ma tran %d lan !

",sg,dem);

            else printf("

gia tri %d khong co trong ma tran!

",sg);

     close(fd);

}

int convert(char c){

return (int)c-48;

}

BÀI40

#include "stdio.h"

#include "sys/types.h"

#include "fcntl.h"

#include "string.h"

#include "sys/file.h"

int convert(char),sapxep(int h[100],int l);

main(){

  int fd,sg=0,k=0,sg2=1,d[100];

  char i[10],s[100];

      printf("nhap vao file day so:");

      fflush(stdin);

      gets(s);

      fd=open(s,O_RDONLY);

      while (sg2!=0){

            sg2=read(fd,i,1);

            if(sg2!=0){

                  if(((int)i[0] != 32)&&((int)i[0] != 10))

                  k=k+1;

                  d[k]=0;

                  while(((int)i[0] != 32)&&((int)i[0] != 10))    

                  {

                        d[k]=d[k]*10+convert(i[0]);

                        sg2=read(fd,i,1);

                  }

            }

      }

      sapxep(d,k);

      for(sg=1;sg<=k;sg++) printf("%d ",d[sg]);

     close(fd);

}

int convert(char c){

return (int)c-48;

}

int sapxep(int h[100],int l){

int s1,l1,l2,tg;

for(l1=1;l1<=l;l1++)

      for(l2=l1;l2<=l;l2++ )

            if (h[l1]>=h[l2]){

                  tg=h[l1];

                  h[l1]=h[l2];

                  h[l2]=tg;

            }

return 0;

}                      

BÀI 41

#include "stdio.h"

#include "sys/types.h"

#include "fcntl.h"

#include "string.h"

#include "sys/file.h"

int convert(char);

main(){

  int fd,sg=0,k=1,sg2=1,d[10];

  char i[10],s[100];

      printf("nhap vao file ma tran:");

      fflush(stdin);

      gets(s);

      fd=open(s,O_RDONLY);

      while (sg2!=0){

            sg2=read(fd,i,1);

            if(sg2!=0){

                  d[k]=0;

                  while (((int)i[0]!=10)){

                        if(((int)i[0] != 32))  

                        {

                        printf("%d ",convert(i[0]));

                        d[k]=d[k]+convert(i[0]);

                        }

                        sg2=read(fd,i,1);

                  }

                  printf("tong cac phan tu trong ma tran hang thu %d la : %d

",k,d[k]);

                  if((int)i[0]==10) k=k+1;

            }

      }

     close(fd);

}

int convert(char c){

return (int)c-48;

}

BÀI 42

#include "stdio.h"

main(){

system("ps -l");

nice(1);

printf("

-----sau khi tang len 1--------------

");

system("ps -l");

nice(2);

printf("

------sau khi tang len 2-------------

");

system("ps -l");

nice(-1);

printf("

________sau khi giam 1_______________

");

system("ps -l");

}

BÀI43

#include "sys/types.h"

#include "stdio.h"

#include "signal.h"

main(){

alarm(3);

}

BÀI 44

#include "sys/types.h"

#include "stdio.h"

#include "signal.h"

main(){

sleep(3);

}

BÀI 45

#include "sys/types.h"

#include "stdio.h"

#include "signal.h"

void SignalAlarm();

int sig=1;

main(){

      signal(SIGALRM,SignalAlarm);

      alarm(10);

      while(sig){

            printf("

doi tin hieu ALARM...");

      }

}

void SignalAlarm(){

sig=0;

}

BÀI46

#include "stdio.h"

#include "signal.h"

main(){

      void (*oldHandler)();

      printf("tu day duoc bao ve ngat SIGINT...:");

      sleep(5);  

      oldHandler=signal(SIGINT,SIG_IGN);

            printf("

tin hieu ngat dc khoi phuc");

      sleep(5);

      signal(SIGINT,oldHandler);

      printf("

ban co the ngat SIGINT");

      sleep(5);

      printf("

ok

");

}

BAI47

#include "stdio.h"

#include "sys/types.h"

main(){

int sg,g;

char f[100];

      printf("nhap vao ten file can thay doi quyen so huu:");

        fflush(stdin);

        gets(f);

 printf("

nhap vao quyen so huu can thay doi cho file da nhap :");

      scanf("%d",&g);

      sg=chmod(f,g);

      if(sg==-1) printf("

thay doi khong thanh cong!");

            else printf("

Thay doi thanh cong !");

}    

BÀI48

#include "stdio.h"

#include "sys/types.h"

main(){

int sg,u;

char f[100];

      printf("nhap vao ten file can thay doi chu so huu:");

        fflush(stdin);

        gets(f);

      printf("

nhap vao ten chu so huu can thay doi cho file da nhap :");

      scanf("%d",&u);

      sg=chown(f,u,getgid());

      if(sg==-1) printf("

thay doi khong thanh cong!");

            else printf("

Thay doi thanh cong !");

}    

BÀI49

#include "stdio.h"

#include "sys/types.h"

main(){

int sg,g;

char f[100];

      printf("nhap vao ten file can thay doi nhom so huu:");

        fflush(stdin);

        gets(f);

      printf("

nhap vao ten nhom so huu can thay doi cho file da nhap :");

      scanf("%d",&g);

      sg=chown(f,getuid(),g);

      if(sg==-1) printf("

thay doi khong thanh cong!");

            else printf("

Thay doi thanh cong !");

}     

Bạn đang đọc truyện trên: Truyen247.Pro

Tags: