SCR
This commit is contained in:
18
TP4/Ex1:/filexec.c
Normal file
18
TP4/Ex1:/filexec.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
int main(int argc, char* argv[]){
|
||||
for(int i=3;i<argc;i++){
|
||||
wait(NULL);
|
||||
pid_t p = fork();
|
||||
if(p==0){
|
||||
execl(argv[1],argv[1],argv[2],argv[i],NULL);
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
BIN
TP4/Ex1:/parexec
Executable file
BIN
TP4/Ex1:/parexec
Executable file
Binary file not shown.
18
TP4/Ex1:/parexec.c
Normal file
18
TP4/Ex1:/parexec.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
int main(int argc, char* argv[]){
|
||||
for(int i=2;i<argc;i++){
|
||||
wait(NULL);
|
||||
pid_t p = fork();
|
||||
if(p==0){
|
||||
execl(argv[1],argv[1],argv[i],NULL);
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
BIN
TP4/Ex1:/rebours
Executable file
BIN
TP4/Ex1:/rebours
Executable file
Binary file not shown.
19
TP4/Ex1:/rebours.c
Normal file
19
TP4/Ex1:/rebours.c
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
assert(argc == 2);
|
||||
|
||||
int value = strtol(argv[1], NULL, 0);
|
||||
pid_t p = getpid();
|
||||
printf("%d: debut\n",p);
|
||||
for(int i = value; i>0; i--){
|
||||
printf("%d: %d\n",p,i);
|
||||
sleep(1);
|
||||
}
|
||||
printf("%d: fin\n",p);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
BIN
TP4/Ex2/pi
Executable file
BIN
TP4/Ex2/pi
Executable file
Binary file not shown.
31
TP4/Ex2/pi.c
Normal file
31
TP4/Ex2/pi.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <signal.h>
|
||||
|
||||
uint64_t shots_in=0,shots=0;
|
||||
double x,y;
|
||||
|
||||
void signalrm_handler(int n){
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
shots_in = 0;
|
||||
shots = 0;
|
||||
for (;;){
|
||||
x = rand()/(RAND_MAX*1.0);
|
||||
y = rand()/(RAND_MAX*1.0);
|
||||
shots ++;
|
||||
if ((x*x+y*y)<=1){
|
||||
shots_in ++;
|
||||
}
|
||||
}
|
||||
/* la probabilité vaut tirsIn/tirs,
|
||||
Elle converge lentement vers pi/4*/
|
||||
}
|
Reference in New Issue
Block a user