Compare commits
2 Commits
e2d2e17407
...
e8e867b878
Author | SHA1 | Date | |
---|---|---|---|
e8e867b878 | |||
96b3c953f8 |
65
DEV/DEV3.1/TP01/Exercise1/Database.java
Normal file
65
DEV/DEV3.1/TP01/Exercise1/Database.java
Normal file
@@ -0,0 +1,65 @@
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class Database {
|
||||
|
||||
//Countries
|
||||
public static String COUNTRY_ID = "id";
|
||||
public static String COUNTRY_NAME = "name";
|
||||
|
||||
//Votes table
|
||||
public static String VOTES_COMPETITOR_ID = "competitor_id";
|
||||
public static String VOTES_VOTER_ID = "voter_id";
|
||||
public static String VOTES_POINTS = "points";
|
||||
|
||||
private Connection connection;
|
||||
|
||||
public Database() {
|
||||
try {
|
||||
Class.forName("org.mariadb.jdbc.Driver");
|
||||
|
||||
this.connection = DriverManager.getConnection(
|
||||
"jdbc:mariadb://dwarves.iut-fbleau.fr/baudrier",
|
||||
"baudrier",
|
||||
"baudrier"
|
||||
);
|
||||
} catch(ClassNotFoundException exception) {
|
||||
System.err.println("Class 'org.mariadb.jdbc.Driver' not found.");
|
||||
} catch(SQLException exception) {
|
||||
System.err.println("Error while trying to connect to the database");
|
||||
}
|
||||
}
|
||||
|
||||
public ResultSet getVotesFromCompetitor(String country) {
|
||||
try {
|
||||
PreparedStatement query = this.connection.prepareStatement(
|
||||
"SELECT Countries.name, Countries.points FROM Votes INNER JOIN Countries ON Votes.competitor_id = Countries.id WHERE Votes.competitor_id = Countries.id"
|
||||
);
|
||||
|
||||
ResultSet result = query.executeQuery();
|
||||
|
||||
try {
|
||||
query.close();
|
||||
} catch(SQLException exception) {
|
||||
System.err.println("Error while trying to close the query.");
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch(SQLException exception) {
|
||||
System.err.println("Error while trying to prepare or execute the query.");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
try {
|
||||
this.connection.close();
|
||||
} catch(SQLException exception) {
|
||||
System.err.println("Error while trying to close the connection.");
|
||||
}
|
||||
}
|
||||
}
|
26
DEV/DEV3.1/TP01/Exercise1/Main.java
Normal file
26
DEV/DEV3.1/TP01/Exercise1/Main.java
Normal file
@@ -0,0 +1,26 @@
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Database database = new Database();
|
||||
|
||||
String country = "France";
|
||||
ResultSet result = database.getVotesFromCompetitor(country);
|
||||
|
||||
try {
|
||||
while(result.next()) {
|
||||
System.out.println(country + " -> " + result.getString("name") + " : " + result.getInt("points"));
|
||||
}
|
||||
} catch(SQLException exception) {
|
||||
System.err.println("Error while read the data from the result.");
|
||||
}
|
||||
|
||||
try {
|
||||
result.close();
|
||||
} catch(SQLException exception) {
|
||||
System.err.println("Error while trying to close the result.");
|
||||
}
|
||||
}
|
||||
}
|
23
DEV/DEV3.1/TP01/Exercise1/data.sql
Normal file
23
DEV/DEV3.1/TP01/Exercise1/data.sql
Normal file
@@ -0,0 +1,23 @@
|
||||
CREATE TABLE Countries (
|
||||
id INT PRIMARY KEY,
|
||||
name VARCHAR(30)
|
||||
);
|
||||
|
||||
CREATE TABLE Votes (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
competitor_id INT REFERENCES Countries(id),
|
||||
voter_id INT REFERENCES Countries(id),
|
||||
points INT NOT NULL,
|
||||
UNIQUE (competitor_id, voter_id)
|
||||
)
|
||||
|
||||
INSERT INTO Countries VALUES (1, "France");
|
||||
INSERT INTO Countries VALUES (2, "Pays-Bas");
|
||||
INSERT INTO Countries VALUES (3, "Albanie");
|
||||
INSERT INTO Countries VALUES (4, "Italie");
|
||||
INSERT INTO Countries VALUES (5, "Russie");
|
||||
INSERT INTO Votes VALUES (2, 4, 5);
|
||||
INSERT INTO Votes VALUES (2, 5, 5);
|
||||
INSERT INTO Votes VALUES (4, 2, 16);
|
||||
INSERT INTO Votes VALUES (5, 2, 5);
|
||||
INSERT INTO Votes VALUES (5, 4, 8);
|
2
DEV/DEV3.1/TP01/Exercise1/start.sh
Executable file
2
DEV/DEV3.1/TP01/Exercise1/start.sh
Executable file
@@ -0,0 +1,2 @@
|
||||
javac Main.java;
|
||||
java -cp "/export/documents/mariadb-client.jar" Main;
|
20
DEV/DEV3.1/TP02/Exercise1/Part1/ClickSwapImageEvent.java
Normal file
20
DEV/DEV3.1/TP02/Exercise1/Part1/ClickSwapImageEvent.java
Normal file
@@ -0,0 +1,20 @@
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class ClickSwapImageEvent extends MouseAdapter {
|
||||
|
||||
private ImageWindow window;
|
||||
|
||||
public ClickSwapImageEvent(ImageWindow window) {
|
||||
this.window = window;
|
||||
}
|
||||
|
||||
public void mouseClicked(MouseEvent event) {
|
||||
if(event.getX() > this.window.getWidth() / 2) {
|
||||
this.window.nextImage();
|
||||
return;
|
||||
}
|
||||
|
||||
this.window.lastImage();
|
||||
}
|
||||
}
|
87
DEV/DEV3.1/TP02/Exercise1/Part1/ImageWindow.java
Normal file
87
DEV/DEV3.1/TP02/Exercise1/Part1/ImageWindow.java
Normal file
@@ -0,0 +1,87 @@
|
||||
import java.io.File;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
|
||||
public class ImageWindow extends JFrame {
|
||||
|
||||
private ImageIcon[] images;
|
||||
private int cursor;
|
||||
|
||||
private JLabel label;
|
||||
|
||||
public ImageWindow() {
|
||||
this.setSize(1024, 1024);
|
||||
this.setLocationRelativeTo(null);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
File resourcesDirectory = new File("../resources/");
|
||||
|
||||
if(resourcesDirectory.exists() && resourcesDirectory.isDirectory()) {
|
||||
File[] files = resourcesDirectory.listFiles();
|
||||
|
||||
if(files != null) {
|
||||
this.images = new ImageIcon[files.length];
|
||||
this.cursor = 0;
|
||||
|
||||
for(File file : files) {
|
||||
this.images[this.cursor] = new ImageIcon(file.getPath());
|
||||
this.cursor++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.addMouseListener(new ClickSwapImageEvent(this));
|
||||
|
||||
this.cursor = 0;
|
||||
|
||||
this.nextImage();
|
||||
}
|
||||
|
||||
public void nextImage() {
|
||||
if(this.images.length == 0) return;
|
||||
|
||||
if(this.label != null) {
|
||||
this.remove(this.label);
|
||||
}
|
||||
|
||||
this.label = new JLabel(this.images[cursor]);
|
||||
this.label.setVerticalAlignment(JLabel.CENTER);
|
||||
this.label.setHorizontalAlignment(JLabel.CENTER);
|
||||
|
||||
if(this.cursor + 1 >= this.images.length) {
|
||||
this.cursor = 0;
|
||||
} else {
|
||||
this.cursor++;
|
||||
}
|
||||
|
||||
System.out.println(this.cursor);
|
||||
|
||||
this.add(label);
|
||||
this.revalidate();
|
||||
}
|
||||
|
||||
public void lastImage() {
|
||||
if(this.images.length == 0) return;
|
||||
|
||||
if(this.label != null) {
|
||||
this.remove(this.label);
|
||||
}
|
||||
|
||||
this.label = new JLabel(this.images[cursor]);
|
||||
this.label.setVerticalAlignment(JLabel.CENTER);
|
||||
this.label.setHorizontalAlignment(JLabel.CENTER);
|
||||
|
||||
if(this.cursor - 1 < 0) {
|
||||
this.cursor = this.images.length - 1;
|
||||
} else {
|
||||
this.cursor--;
|
||||
}
|
||||
|
||||
System.out.println(this.cursor);
|
||||
|
||||
this.add(label);
|
||||
this.revalidate();
|
||||
}
|
||||
}
|
7
DEV/DEV3.1/TP02/Exercise1/Part1/Main.java
Normal file
7
DEV/DEV3.1/TP02/Exercise1/Part1/Main.java
Normal file
@@ -0,0 +1,7 @@
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
ImageWindow window = new ImageWindow();
|
||||
window.setVisible(true);
|
||||
}
|
||||
}
|
5
DEV/DEV3.1/TP02/Exercise1/Part2/ClickSwapImageEvent.java
Normal file
5
DEV/DEV3.1/TP02/Exercise1/Part2/ClickSwapImageEvent.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package Part2;
|
||||
|
||||
public class ClickSwapImageEvent {
|
||||
|
||||
}
|
26
DEV/DEV3.1/TP02/Exercise1/Part2/ImageWindow.java
Normal file
26
DEV/DEV3.1/TP02/Exercise1/Part2/ImageWindow.java
Normal file
@@ -0,0 +1,26 @@
|
||||
import java.io.File;
|
||||
|
||||
import java.awt.CardLayout;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
public class ImageWindow extends JFrame {
|
||||
|
||||
private CardLayout card;
|
||||
|
||||
public ImageWindow() {
|
||||
this.card = new CardLayout();
|
||||
|
||||
File resourcesDirectory = new File("../resources/");
|
||||
|
||||
if(resourcesDirectory.exists() && resourcesDirectory.isDirectory()) {
|
||||
File[] files = resourcesDirectory.listFiles();
|
||||
|
||||
if(files != null) {
|
||||
for(File file : files) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
5
DEV/DEV3.1/TP02/Exercise1/Part2/Main.java
Normal file
5
DEV/DEV3.1/TP02/Exercise1/Part2/Main.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package Part2;
|
||||
|
||||
public class Main {
|
||||
|
||||
}
|
BIN
DEV/DEV3.1/TP02/Exercise1/resources/dice.jpg
Normal file
BIN
DEV/DEV3.1/TP02/Exercise1/resources/dice.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 70 KiB |
BIN
DEV/DEV3.1/TP02/Exercise1/resources/frog.png
Normal file
BIN
DEV/DEV3.1/TP02/Exercise1/resources/frog.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
BIN
DEV/DEV3.1/TP02/Exercise1/resources/random.jpg
Normal file
BIN
DEV/DEV3.1/TP02/Exercise1/resources/random.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.6 KiB |
55
SCR/SCR3.1/TP01/Exercise1/answer.txt
Normal file
55
SCR/SCR3.1/TP01/Exercise1/answer.txt
Normal file
@@ -0,0 +1,55 @@
|
||||
[baudrier@salle224-14 Exercise1]$ gcc virtual_adress.c
|
||||
[baudrier@salle224-14 Exercise1]$ ./a.out
|
||||
je suis le pid 157247
|
||||
|
||||
main = 0x56435b8ae179
|
||||
gettimeofday = 0x7fbdaf0c6870
|
||||
&argc = 0x7ffcf1b50e1c
|
||||
&i = 0x7ffcf1b50e2c
|
||||
&j = 0x56435b8b2000
|
||||
t = 0x56435b8b1060
|
||||
m = 0x56435ff42310
|
||||
|
||||
[baudrier@salle224-14 BUT2]$ cat /proc/157247/maps
|
||||
56435b8ad000-56435b8ae000 r--p 00000000 00:3e 22477647 /export/home/info-but24/baudrier/Documents/BUT2/SCR/SCR3.1/TP01/Exercise1/a.out
|
||||
56435b8ae000-56435b8af000 r-xp 00001000 00:3e 22477647 /export/home/info-but24/baudrier/Documents/BUT2/SCR/SCR3.1/TP01/Exercise1/a.out
|
||||
56435b8af000-56435b8b0000 r--p 00002000 00:3e 22477647 /export/home/info-but24/baudrier/Documents/BUT2/SCR/SCR3.1/TP01/Exercise1/a.out
|
||||
56435b8b0000-56435b8b1000 r--p 00002000 00:3e 22477647 /export/home/info-but24/baudrier/Documents/BUT2/SCR/SCR3.1/TP01/Exercise1/a.out
|
||||
56435b8b1000-56435b8b3000 rw-p 00003000 00:3e 22477647 /export/home/info-but24/baudrier/Documents/BUT2/SCR/SCR3.1/TP01/Exercise1/a.out
|
||||
56435ff42000-56435ff63000 rw-p 00000000 00:00 0 [heap]
|
||||
7fbdaee00000-7fbdaee24000 r--p 00000000 103:05 6028 /usr/lib/libc.so.6
|
||||
7fbdaee24000-7fbdaef96000 r-xp 00024000 103:05 6028 /usr/lib/libc.so.6
|
||||
7fbdaef96000-7fbdaf005000 r--p 00196000 103:05 6028 /usr/lib/libc.so.6
|
||||
7fbdaf005000-7fbdaf009000 r--p 00204000 103:05 6028 /usr/lib/libc.so.6
|
||||
7fbdaf009000-7fbdaf00b000 rw-p 00208000 103:05 6028 /usr/lib/libc.so.6
|
||||
7fbdaf00b000-7fbdaf013000 rw-p 00000000 00:00 0
|
||||
7fbdaf08f000-7fbdaf094000 rw-p 00000000 00:00 0
|
||||
7fbdaf0c0000-7fbdaf0c4000 r--p 00000000 00:00 0 [vvar]
|
||||
7fbdaf0c4000-7fbdaf0c6000 r--p 00000000 00:00 0 [vvar_vclock]
|
||||
7fbdaf0c6000-7fbdaf0c8000 r-xp 00000000 00:00 0 [vdso]
|
||||
7fbdaf0c8000-7fbdaf0c9000 r--p 00000000 103:05 6019 /usr/lib/ld-linux-x86-64.so.2
|
||||
7fbdaf0c9000-7fbdaf0f3000 r-xp 00001000 103:05 6019 /usr/lib/ld-linux-x86-64.so.2
|
||||
7fbdaf0f3000-7fbdaf101000 r--p 0002b000 103:05 6019 /usr/lib/ld-linux-x86-64.so.2
|
||||
7fbdaf101000-7fbdaf103000 r--p 00039000 103:05 6019 /usr/lib/ld-linux-x86-64.so.2
|
||||
7fbdaf103000-7fbdaf104000 rw-p 0003b000 103:05 6019 /usr/lib/ld-linux-x86-64.so.2
|
||||
7fbdaf104000-7fbdaf105000 rw-p 00000000 00:00 0
|
||||
7ffcf1b32000-7ffcf1b53000 rw-p 00000000 00:00 0 [stack]
|
||||
ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0 [vsyscall]
|
||||
|
||||
- main appartient au segment de pages : 56435b8ae000-56435b8af000 r-xp 00001000 00:3e 22477647 /export/home/info-but24/baudrier/Documents/BUT2/SCR/SCR3.1/TP01/Exercise1/a.out
|
||||
-> C'est une fonction (donc du code) qui appartient au fichier a.out, et qui a besoin des droits d'exécutions (il a bien la permission 'x').
|
||||
|
||||
- gettimeofday : 7fbdaf0c6000-7fbdaf0c8000 r-xp 00000000 00:00 0 [vdso]
|
||||
-> Code du noyau, exécuté par le noyau
|
||||
|
||||
- &argc : 7ffcf1b32000-7ffcf1b53000 rw-p 00000000 00:00 0 [stack]
|
||||
-> Argument de la fonction main(), se trouve dans la pile (stack)
|
||||
|
||||
- &i : 7ffcf1b32000-7ffcf1b53000 rw-p 00000000 00:00 0 [stack]
|
||||
|
||||
- &j : 56435b8b1000-56435b8b3000 rw-p 00003000 00:3e 22477647 /export/home/info-but24/baudrier/Documents/BUT2/SCR/SCR3.1/TP01/Exercise1/a.out
|
||||
|
||||
- t : 56435b8b0000-56435b8b1000 r--p 00002000 00:3e 22477647 /export/home/info-but24/baudrier/Documents/BUT2/SCR/SCR3.1/TP01/Exercise1/a.out
|
||||
|
||||
- m : 56435ff42000-56435ff63000 rw-p 00000000 00:00 0 [heap]
|
||||
-> malloc() attribue de la mémoire dans le tas (heap)
|
27
SCR/SCR3.1/TP01/Exercise1/virtual_adress.c
Normal file
27
SCR/SCR3.1/TP01/Exercise1/virtual_adress.c
Normal file
@@ -0,0 +1,27 @@
|
||||
/* adresses virtuelles d'un processus */
|
||||
|
||||
#include<stdio.h>
|
||||
#include<sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include<unistd.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
int t[1000] = {[0 ... 999] = 2};
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
int i=3;
|
||||
static int j = 3;
|
||||
char * m = (char*)malloc(1);
|
||||
printf("je suis le pid %d\n\n",getpid());
|
||||
/* ------- Affichage des adresses --------*/
|
||||
printf("main\t\t=\t%p\n",main);
|
||||
printf("gettimeofday\t=\t%p\n",gettimeofday);
|
||||
printf("&argc\t\t=\t%p\n",&argc);
|
||||
printf("&i\t\t=\t%p\n",&i);
|
||||
printf("&j\t\t=\t%p\n",&j);
|
||||
printf("t\t\t=\t%p\n",t);
|
||||
printf("m\t\t=\t%p\n",m);
|
||||
|
||||
getchar();
|
||||
}
|
189
SCR/SCR3.1/TP01/Exercise2/answer.txt
Normal file
189
SCR/SCR3.1/TP01/Exercise2/answer.txt
Normal file
@@ -0,0 +1,189 @@
|
||||
- Stack -
|
||||
[baudrier@salle224-14 BUT2]$ pmap -x 16088
|
||||
16088: ./stack
|
||||
Address Kbytes RSS Dirty Mode Mapping
|
||||
000055fc39741000 4 4 0 r---- stack
|
||||
000055fc39742000 4 4 0 r-x-- stack
|
||||
000055fc39743000 4 4 0 r---- stack
|
||||
000055fc39744000 4 4 4 r---- stack
|
||||
000055fc39745000 4 4 4 rw--- stack
|
||||
000055fc55245000 132 4 4 rw--- [ anon ]
|
||||
00007fb88b000000 144 144 0 r---- libc.so.6
|
||||
00007fb88b024000 1480 1060 0 r-x-- libc.so.6
|
||||
00007fb88b196000 444 128 0 r---- libc.so.6
|
||||
00007fb88b205000 16 16 16 r---- libc.so.6
|
||||
00007fb88b209000 8 8 8 rw--- libc.so.6
|
||||
00007fb88b20b000 32 20 20 rw--- [ anon ]
|
||||
00007fb88b353000 20 12 12 rw--- [ anon ]
|
||||
00007fb88b384000 16 0 0 r---- [ anon ]
|
||||
00007fb88b388000 8 0 0 r---- [ anon ]
|
||||
00007fb88b38a000 8 8 0 r-x-- [ anon ]
|
||||
00007fb88b38c000 4 4 0 r---- ld-linux-x86-64.so.2
|
||||
00007fb88b38d000 168 168 0 r-x-- ld-linux-x86-64.so.2
|
||||
00007fb88b3b7000 56 56 0 r---- ld-linux-x86-64.so.2
|
||||
00007fb88b3c5000 8 8 8 r---- ld-linux-x86-64.so.2
|
||||
00007fb88b3c7000 4 4 4 rw--- ld-linux-x86-64.so.2
|
||||
00007fb88b3c8000 4 4 4 rw--- [ anon ]
|
||||
00007ffcc07fd000 132 36 36 rw--- [ stack ]
|
||||
ffffffffff600000 4 0 0 --x-- [ anon ]
|
||||
---------------- ------- ------- -------
|
||||
total kB 2708 1700 120
|
||||
|
||||
- MMAP -
|
||||
[baudrier@salle224-14 BUT2]$ pmap -x 17734
|
||||
17734: ./mmap
|
||||
Address Kbytes RSS Dirty Mode Mapping
|
||||
000055e00c982000 4 4 0 r---- mmap
|
||||
000055e00c983000 4 4 0 r-x-- mmap
|
||||
000055e00c984000 4 4 0 r---- mmap
|
||||
000055e00c985000 4 4 4 r---- mmap
|
||||
000055e00c986000 4 4 4 rw--- mmap
|
||||
000055e020dd6000 132 4 4 rw--- [ anon ]
|
||||
00007f2007800000 144 144 0 r---- libc.so.6
|
||||
00007f2007824000 1480 1060 0 r-x-- libc.so.6
|
||||
00007f2007996000 444 128 0 r---- libc.so.6
|
||||
00007f2007a05000 16 16 16 r---- libc.so.6
|
||||
00007f2007a09000 8 8 8 rw--- libc.so.6
|
||||
00007f2007a0b000 32 20 20 rw--- [ anon ]
|
||||
00007f2007b2b000 256 128 128 rw--- 256k
|
||||
00007f2007b6b000 20 12 12 rw--- [ anon ]
|
||||
00007f2007b80000 64 64 64 rw-s- zero (deleted)
|
||||
00007f2007b90000 48 32 32 rw--- [ anon ]
|
||||
00007f2007b9c000 16 0 0 r---- [ anon ]
|
||||
00007f2007ba0000 8 0 0 r---- [ anon ]
|
||||
00007f2007ba2000 8 8 0 r-x-- [ anon ]
|
||||
00007f2007ba4000 4 4 0 r---- ld-linux-x86-64.so.2
|
||||
00007f2007ba5000 168 168 0 r-x-- ld-linux-x86-64.so.2
|
||||
00007f2007bcf000 56 56 0 r---- ld-linux-x86-64.so.2
|
||||
00007f2007bdd000 8 8 8 r---- ld-linux-x86-64.so.2
|
||||
00007f2007bdf000 4 4 4 rw--- ld-linux-x86-64.so.2
|
||||
00007f2007be0000 4 4 4 rw--- [ anon ]
|
||||
00007ffcfccb6000 132 16 16 rw--- [ stack ]
|
||||
ffffffffff600000 4 0 0 --x-- [ anon ]
|
||||
---------------- ------- ------- -------
|
||||
total kB 3076 1904 324
|
||||
|
||||
- Huge -
|
||||
[baudrier@salle224-14 BUT2]$ pmap -x 18284
|
||||
18284: ./huge
|
||||
Address Kbytes RSS Dirty Mode Mapping
|
||||
0000555e2f729000 4 4 0 r---- huge
|
||||
0000555e2f72a000 4 4 0 r-x-- huge
|
||||
0000555e2f72b000 4 4 0 r---- huge
|
||||
0000555e2f72c000 4 4 4 r---- huge
|
||||
0000555e2f72d000 4 4 4 rw--- huge
|
||||
0000555e40ba4000 228 100 100 rw--- [ anon ]
|
||||
00007f2f5d400000 144 144 0 r---- libc.so.6
|
||||
00007f2f5d424000 1480 1060 0 r-x-- libc.so.6
|
||||
00007f2f5d596000 444 128 0 r---- libc.so.6
|
||||
00007f2f5d605000 16 16 16 r---- libc.so.6
|
||||
00007f2f5d609000 8 8 8 rw--- libc.so.6
|
||||
00007f2f5d60b000 32 20 20 rw--- [ anon ]
|
||||
00007f2f5d757000 280 272 272 rw--- [ anon ]
|
||||
00007f2f5d7c9000 16 0 0 r---- [ anon ]
|
||||
00007f2f5d7cd000 8 0 0 r---- [ anon ]
|
||||
00007f2f5d7cf000 8 8 0 r-x-- [ anon ]
|
||||
00007f2f5d7d1000 4 4 0 r---- ld-linux-x86-64.so.2
|
||||
00007f2f5d7d2000 168 168 0 r-x-- ld-linux-x86-64.so.2
|
||||
00007f2f5d7fc000 56 56 0 r---- ld-linux-x86-64.so.2
|
||||
00007f2f5d80a000 8 8 8 r---- ld-linux-x86-64.so.2
|
||||
00007f2f5d80c000 4 4 4 rw--- ld-linux-x86-64.so.2
|
||||
00007f2f5d80d000 4 4 4 rw--- [ anon ]
|
||||
00007ffdcfdcf000 132 16 16 rw--- [ stack ]
|
||||
ffffffffff600000 4 0 0 --x-- [ anon ]
|
||||
---------------- ------- ------- -------
|
||||
total kB 3064 2036 456
|
||||
|
||||
- Null -
|
||||
[baudrier@salle224-14 BUT2]$ pmap -x 18519
|
||||
18519: ./null
|
||||
Address Kbytes RSS Dirty Mode Mapping
|
||||
0000561bf65bf000 4 4 0 r---- null
|
||||
0000561bf65c0000 4 4 0 r-x-- null
|
||||
0000561bf65c1000 4 4 0 r---- null
|
||||
0000561bf65c2000 4 4 4 r---- null
|
||||
0000561bf65c3000 4 4 4 rw--- null
|
||||
0000561c26834000 132 4 4 rw--- [ anon ]
|
||||
00007f293fa00000 144 144 0 r---- libc.so.6
|
||||
00007f293fa24000 1480 1060 0 r-x-- libc.so.6
|
||||
00007f293fb96000 444 128 0 r---- libc.so.6
|
||||
00007f293fc05000 16 16 16 r---- libc.so.6
|
||||
00007f293fc09000 8 8 8 rw--- libc.so.6
|
||||
00007f293fc0b000 32 20 20 rw--- [ anon ]
|
||||
00007f293fca6000 20 12 12 rw--- [ anon ]
|
||||
00007f293fcd7000 16 0 0 r---- [ anon ]
|
||||
00007f293fcdb000 8 0 0 r---- [ anon ]
|
||||
00007f293fcdd000 8 8 0 r-x-- [ anon ]
|
||||
00007f293fcdf000 4 4 0 r---- ld-linux-x86-64.so.2
|
||||
00007f293fce0000 168 168 0 r-x-- ld-linux-x86-64.so.2
|
||||
00007f293fd0a000 56 56 0 r---- ld-linux-x86-64.so.2
|
||||
00007f293fd18000 8 8 8 r---- ld-linux-x86-64.so.2
|
||||
00007f293fd1a000 4 4 4 rw--- ld-linux-x86-64.so.2
|
||||
00007f293fd1b000 4 4 4 rw--- [ anon ]
|
||||
00007ffe4e9df000 132 16 16 rw--- [ stack ]
|
||||
ffffffffff600000 4 0 0 --x-- [ anon ]
|
||||
---------------- ------- ------- -------
|
||||
total kB 2708 1680 100
|
||||
|
||||
- Heap -
|
||||
[baudrier@salle224-14 BUT2]$ pmap -x 18846
|
||||
18846: ./heap
|
||||
Address Kbytes RSS Dirty Mode Mapping
|
||||
00005571639f9000 4 4 0 r---- heap
|
||||
00005571639fa000 4 4 0 r-x-- heap
|
||||
00005571639fb000 4 4 0 r---- heap
|
||||
00005571639fc000 4 4 4 r---- heap
|
||||
00005571639fd000 4 4 4 rw--- heap
|
||||
000055717e499000 50028 49924 49924 rw--- [ anon ]
|
||||
00007f485aa00000 144 144 0 r---- libc.so.6
|
||||
00007f485aa24000 1480 1060 0 r-x-- libc.so.6
|
||||
00007f485ab96000 444 128 0 r---- libc.so.6
|
||||
00007f485ac05000 16 16 16 r---- libc.so.6
|
||||
00007f485ac09000 8 8 8 rw--- libc.so.6
|
||||
00007f485ac0b000 32 20 20 rw--- [ anon ]
|
||||
00007f485ad82000 20 12 12 rw--- [ anon ]
|
||||
00007f485adb3000 16 0 0 r---- [ anon ]
|
||||
00007f485adb7000 8 0 0 r---- [ anon ]
|
||||
00007f485adb9000 8 8 0 r-x-- [ anon ]
|
||||
00007f485adbb000 4 4 0 r---- ld-linux-x86-64.so.2
|
||||
00007f485adbc000 168 168 0 r-x-- ld-linux-x86-64.so.2
|
||||
00007f485ade6000 56 56 0 r---- ld-linux-x86-64.so.2
|
||||
00007f485adf4000 8 8 8 r---- ld-linux-x86-64.so.2
|
||||
00007f485adf6000 4 4 4 rw--- ld-linux-x86-64.so.2
|
||||
00007f485adf7000 4 4 4 rw--- [ anon ]
|
||||
00007fffd8762000 132 16 16 rw--- [ stack ]
|
||||
ffffffffff600000 4 0 0 --x-- [ anon ]
|
||||
---------------- ------- ------- -------
|
||||
total kB 52604 51600 50020
|
||||
|
||||
- Buf -
|
||||
[baudrier@salle224-14 BUT2]$ pmap -x 19569
|
||||
19569: ./buf
|
||||
Address Kbytes RSS Dirty Mode Mapping
|
||||
000056423e617000 4 4 0 r---- buf
|
||||
000056423e618000 4 4 0 r-x-- buf
|
||||
000056423e619000 4 4 0 r---- buf
|
||||
000056423e61a000 4 4 4 r---- buf
|
||||
000056423e61b000 4 4 4 rw--- buf
|
||||
000056423e61c000 16384 16384 16384 rw--- [ anon ]
|
||||
0000564255eda000 132 4 4 rw--- [ anon ]
|
||||
00007f576c600000 144 144 0 r---- libc.so.6
|
||||
00007f576c624000 1480 1060 0 r-x-- libc.so.6
|
||||
00007f576c796000 444 128 0 r---- libc.so.6
|
||||
00007f576c805000 16 16 16 r---- libc.so.6
|
||||
00007f576c809000 8 8 8 rw--- libc.so.6
|
||||
00007f576c80b000 32 20 20 rw--- [ anon ]
|
||||
00007f576c8c9000 20 12 12 rw--- [ anon ]
|
||||
00007f576c8fa000 16 0 0 r---- [ anon ]
|
||||
00007f576c8fe000 8 0 0 r---- [ anon ]
|
||||
00007f576c900000 8 8 0 r-x-- [ anon ]
|
||||
00007f576c902000 4 4 0 r---- ld-linux-x86-64.so.2
|
||||
00007f576c903000 168 168 0 r-x-- ld-linux-x86-64.so.2
|
||||
00007f576c92d000 56 56 0 r---- ld-linux-x86-64.so.2
|
||||
00007f576c93b000 8 8 8 r---- ld-linux-x86-64.so.2
|
||||
00007f576c93d000 4 4 4 rw--- ld-linux-x86-64.so.2
|
||||
00007f576c93e000 4 4 4 rw--- [ anon ]
|
||||
00007ffd7eb9e000 132 12 12 rw--- [ stack ]
|
||||
ffffffffff600000 4 0 0 --x-- [ anon ]
|
||||
---------------- ------- ------- -------
|
||||
total kB 19092 18060 16480
|
17
SCR/SCR3.1/TP01/Exercise2/subject/Makefile
Normal file
17
SCR/SCR3.1/TP01/Exercise2/subject/Makefile
Normal file
@@ -0,0 +1,17 @@
|
||||
CFLAGS := -Wall -g -O0
|
||||
SRC=buf.c heap.c huge.c mmap.c null.c stack.c
|
||||
|
||||
DEPENDHELPERS=helpers.o
|
||||
|
||||
BINARIES=$(SRC:%.c=%)
|
||||
|
||||
%.o : %c
|
||||
gcc -c $+
|
||||
|
||||
$(BINARIES): % : %.o $(DEPENDHELPERS)
|
||||
gcc -o $@ $+
|
||||
|
||||
all : $(BINARIES)
|
||||
|
||||
clean:
|
||||
rm -f *.o $(BINARIES)
|
BIN
SCR/SCR3.1/TP01/Exercise2/subject/buf
Executable file
BIN
SCR/SCR3.1/TP01/Exercise2/subject/buf
Executable file
Binary file not shown.
9
SCR/SCR3.1/TP01/Exercise2/subject/buf.c
Normal file
9
SCR/SCR3.1/TP01/Exercise2/subject/buf.c
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "helpers.h"
|
||||
|
||||
static char buffer[16 MB] = {0};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
randomize(buffer, 16 MB);
|
||||
return interlude();
|
||||
}
|
BIN
SCR/SCR3.1/TP01/Exercise2/subject/data/256k
Normal file
BIN
SCR/SCR3.1/TP01/Exercise2/subject/data/256k
Normal file
Binary file not shown.
BIN
SCR/SCR3.1/TP01/Exercise2/subject/heap
Executable file
BIN
SCR/SCR3.1/TP01/Exercise2/subject/heap
Executable file
Binary file not shown.
8
SCR/SCR3.1/TP01/Exercise2/subject/heap.c
Normal file
8
SCR/SCR3.1/TP01/Exercise2/subject/heap.c
Normal file
@@ -0,0 +1,8 @@
|
||||
#include "helpers.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
dirty(16 MB);
|
||||
clean(32 MB);
|
||||
return interlude();
|
||||
}
|
36
SCR/SCR3.1/TP01/Exercise2/subject/helpers.c
Normal file
36
SCR/SCR3.1/TP01/Exercise2/subject/helpers.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include "helpers.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
void randomize(char *buf, size_t n)
|
||||
{
|
||||
assert(buf);
|
||||
memset(buf, rand() & 0xff, n);
|
||||
}
|
||||
|
||||
void clean(size_t b)
|
||||
{
|
||||
for (; b > 0; b -= 1 KB)
|
||||
calloc(1 KB, sizeof(char));
|
||||
}
|
||||
|
||||
void dirty(size_t b)
|
||||
{
|
||||
for (; b > 0; b -= 1 KB)
|
||||
randomize(calloc(1 KB, sizeof(char)), 1 KB);
|
||||
}
|
||||
|
||||
int interlude(void)
|
||||
{
|
||||
pid_t pid = getpid();
|
||||
printf("pid %i\n", (int)pid);
|
||||
printf("------------------------------------------\n"
|
||||
"go check /proc/%i/smaps; I'll wait...\n"
|
||||
"press <Enter> when you're done\n", pid);
|
||||
fgetc(stdin);
|
||||
return 0;
|
||||
}
|
13
SCR/SCR3.1/TP01/Exercise2/subject/helpers.h
Normal file
13
SCR/SCR3.1/TP01/Exercise2/subject/helpers.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef _HELPERS_H
|
||||
#define _HELPERS_H
|
||||
#include <stdlib.h>
|
||||
|
||||
#define KB * 1024
|
||||
#define MB * 1024 * 1024
|
||||
|
||||
void randomize(char *buf, size_t n);
|
||||
void clean(size_t n);
|
||||
void dirty(size_t n);
|
||||
int interlude(void);
|
||||
|
||||
#endif
|
BIN
SCR/SCR3.1/TP01/Exercise2/subject/huge
Executable file
BIN
SCR/SCR3.1/TP01/Exercise2/subject/huge
Executable file
Binary file not shown.
12
SCR/SCR3.1/TP01/Exercise2/subject/huge.c
Normal file
12
SCR/SCR3.1/TP01/Exercise2/subject/huge.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "helpers.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char *under = malloc(96 KB);
|
||||
randomize(under, 96 KB);
|
||||
|
||||
char *over = malloc(256 KB);
|
||||
randomize(over, 256 KB);
|
||||
|
||||
return interlude();
|
||||
}
|
BIN
SCR/SCR3.1/TP01/Exercise2/subject/mmap
Executable file
BIN
SCR/SCR3.1/TP01/Exercise2/subject/mmap
Executable file
Binary file not shown.
38
SCR/SCR3.1/TP01/Exercise2/subject/mmap.c
Normal file
38
SCR/SCR3.1/TP01/Exercise2/subject/mmap.c
Normal file
@@ -0,0 +1,38 @@
|
||||
#include "helpers.h"
|
||||
#include <sys/mman.h>
|
||||
#include <assert.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
/* inert map (never modified) */
|
||||
char *inert = mmap(NULL, 16 KB,
|
||||
PROT_READ|PROT_WRITE,
|
||||
MAP_ANONYMOUS|MAP_PRIVATE,
|
||||
-1, 0);
|
||||
/* anonymous, private mmap */
|
||||
char *anon_priv = mmap(NULL, 32 KB,
|
||||
PROT_READ|PROT_WRITE,
|
||||
MAP_ANONYMOUS|MAP_PRIVATE,
|
||||
-1, 0);
|
||||
randomize(anon_priv, 32 KB);
|
||||
|
||||
/* anonymous, shared map */
|
||||
char *anon_shared = mmap(NULL, 64 KB,
|
||||
PROT_READ|PROT_WRITE,
|
||||
MAP_ANONYMOUS|MAP_SHARED,
|
||||
-1, 0);
|
||||
randomize(anon_shared, 64 KB);
|
||||
|
||||
/* private, file-backed map */
|
||||
int fd = open("data/256k", O_RDWR);
|
||||
assert(fd >= 0);
|
||||
char *file = mmap(NULL, 256 KB,
|
||||
PROT_READ|PROT_WRITE,
|
||||
MAP_PRIVATE,
|
||||
fd, 0);
|
||||
randomize(file, 128 KB);
|
||||
|
||||
return interlude();
|
||||
}
|
BIN
SCR/SCR3.1/TP01/Exercise2/subject/null
Executable file
BIN
SCR/SCR3.1/TP01/Exercise2/subject/null
Executable file
Binary file not shown.
6
SCR/SCR3.1/TP01/Exercise2/subject/null.c
Normal file
6
SCR/SCR3.1/TP01/Exercise2/subject/null.c
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "helpers.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
return interlude();
|
||||
}
|
BIN
SCR/SCR3.1/TP01/Exercise2/subject/stack
Executable file
BIN
SCR/SCR3.1/TP01/Exercise2/subject/stack
Executable file
Binary file not shown.
8
SCR/SCR3.1/TP01/Exercise2/subject/stack.c
Normal file
8
SCR/SCR3.1/TP01/Exercise2/subject/stack.c
Normal file
@@ -0,0 +1,8 @@
|
||||
#include "helpers.h"
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
char buf[28 KB] = {0};
|
||||
randomize(buf, 28 KB);
|
||||
return interlude();
|
||||
}
|
16
SCR/SCR3.1/TP01/Exercise3/answer.txt
Normal file
16
SCR/SCR3.1/TP01/Exercise3/answer.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
- Version 1 -
|
||||
time = 0.149877
|
||||
[baudrier@salle224-14 Exercise3]$ size a.out
|
||||
text data bss dec hex filename
|
||||
1136 512 40032 41680 a2d0 a.out
|
||||
|
||||
- Version 2 -
|
||||
time = 1.313450
|
||||
[baudrier@salle224-14 Exercise3]$ size a.out
|
||||
text data bss dec hex filename
|
||||
1136 40528 8 41672 a2c8 a.out
|
||||
|
||||
-> La version 2 est donc plus longue car dans la deuxième version on doit charger à chaque fois une nouvelle colonne du tableau à chaque itération.
|
||||
-> Alors que dans la version 1, on parcours chaque colonne et chaque éléments de la colonne ensuite.
|
||||
-> Donc dans cette première version le tableau t est dans le segment bss (car il n'est pas initialisé).
|
||||
-> Et dans la deuxième version il est dans le segment data car il est initialisé.
|
26
SCR/SCR3.1/TP01/Exercise3/prog.c
Normal file
26
SCR/SCR3.1/TP01/Exercise3/prog.c
Normal file
@@ -0,0 +1,26 @@
|
||||
/* accès mémoire */
|
||||
#include<stdio.h>
|
||||
#include<time.h>
|
||||
#include <stdlib.h>
|
||||
#define N 8192
|
||||
|
||||
int t[N][N];
|
||||
|
||||
static inline double tstamp(void)
|
||||
{
|
||||
struct timespec tv;
|
||||
clock_gettime(CLOCK_REALTIME, &tv);
|
||||
return tv.tv_sec + tv.tv_nsec * 1.0e-9;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int i,j;
|
||||
double t1,t2;
|
||||
t1=tstamp();
|
||||
/* version 1 */ for(i=0;i<N;i++) for(j=0;j<N;j++) t[i][j] = 1;
|
||||
/* version 2 */ // for(i=0;i<N;i++) for(j=0;j<N;j++) t[j][i] = 1;
|
||||
t2=tstamp();
|
||||
printf("time = %lf\n",t2-t1);
|
||||
return 0;
|
||||
}
|
44
SCR/SCR3.1/TP01/Exercise4/crible.c
Normal file
44
SCR/SCR3.1/TP01/Exercise4/crible.c
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void afficher(char* crible, int n) {
|
||||
for(int i = 0; i < n; i++) {
|
||||
if(crible[i]) printf("%d ", i);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void rayer_multiples(char* crible, int n, int k) {
|
||||
for(int i = 0; i < n; i++) {
|
||||
if(i % k == 0 && i != k) crible[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int n=1000;
|
||||
if(argc>1){
|
||||
n = (int)strtol(argv[1],NULL,0);
|
||||
assert( n > 0 );
|
||||
}
|
||||
|
||||
char* crible = (char*)mmap(NULL, n * sizeof(int), PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, -1, 0);
|
||||
assert(crible != MAP_FAILED);
|
||||
|
||||
for(int i=0; i<n; i++){
|
||||
crible[i] = 1;//par défaut: pas encore barré
|
||||
}
|
||||
|
||||
for(int k=2; k<n; k++){
|
||||
rayer_multiples(crible, n, k);
|
||||
}
|
||||
|
||||
afficher(crible, n);
|
||||
|
||||
return 0;
|
||||
}
|
0
SCR/SCR3.1/TP01/Exercise5/answer.txt
Normal file
0
SCR/SCR3.1/TP01/Exercise5/answer.txt
Normal file
109
SCR/SCR3.1/TP01/Exercise5/sum_array.c
Normal file
109
SCR/SCR3.1/TP01/Exercise5/sum_array.c
Normal file
@@ -0,0 +1,109 @@
|
||||
#include<stdio.h>
|
||||
#include<time.h>
|
||||
#include<stdlib.h>
|
||||
#include<string.h>
|
||||
#include<assert.h>
|
||||
|
||||
static inline double tstamp(void)
|
||||
{
|
||||
struct timespec tv;
|
||||
// clock_gettime(CLOCK_REALTIME, &tv);
|
||||
clock_gettime(CLOCK_MONOTONIC, &tv);
|
||||
return tv.tv_sec + tv.tv_nsec * 1.0e-9;
|
||||
}
|
||||
|
||||
void shuffle(int *array, size_t n)
|
||||
{
|
||||
if (n > 1)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < n - 1; i++)
|
||||
// for (i = 0; i < n ; i++)
|
||||
{
|
||||
size_t j = i + rand() / (RAND_MAX / (n - i) + 1);
|
||||
// size_t j = rand()%n;
|
||||
int t = array[j];
|
||||
array[j] = array[i];
|
||||
array[i] = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void init_access_c(int access[],size_t size)
|
||||
{
|
||||
int i;
|
||||
for(i=0;i<size;i++) access[i] = i;
|
||||
}
|
||||
|
||||
void init_access_d(int access[],size_t size)
|
||||
{
|
||||
int i;
|
||||
for(i=0;i<size;i++) access[i] = size-i-1;
|
||||
}
|
||||
|
||||
void init_access_a(int access[],size_t size)
|
||||
{
|
||||
init_access_c(access,size);
|
||||
shuffle(access,size);
|
||||
}
|
||||
|
||||
void init_array(int t[],int N)
|
||||
{
|
||||
int i;
|
||||
for(i=0;i<N;i++) t[i] = i ;
|
||||
|
||||
}
|
||||
|
||||
long int sum_array(int t[],int access[],size_t size)
|
||||
{
|
||||
long int S=0;
|
||||
int i;
|
||||
for(i=0;i<size;i++) S += t[access[i]];
|
||||
return S;
|
||||
}
|
||||
|
||||
int main(int argc,char * argv[])
|
||||
{
|
||||
double t1,t2;
|
||||
int * array; // tableau à sommer (contient les tous les entiers [0,SIZE-1]
|
||||
int * access;
|
||||
int i,size;
|
||||
long int S=0;
|
||||
|
||||
|
||||
if (argc !=3) {
|
||||
printf("%s -c|-d|-a SIZE\n",argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
size=strtol(argv[2],NULL,0);
|
||||
|
||||
array=(int *)malloc(sizeof(int)*size);
|
||||
assert(array != NULL);
|
||||
|
||||
access=(int *)malloc(sizeof(int)*size);
|
||||
assert(access != NULL);
|
||||
|
||||
|
||||
init_array(array,size);
|
||||
if (strcmp(argv[1],"-c") == 0)
|
||||
init_access_c(access,size);
|
||||
|
||||
if (strcmp(argv[1],"-d") == 0)
|
||||
init_access_d(access,size);
|
||||
|
||||
if (strcmp(argv[1],"-a") == 0)
|
||||
init_access_a(access,size);
|
||||
|
||||
/* On somme les elements en accedant au tableau
|
||||
* sequentiellement (croissant/décroissant), ou
|
||||
* de manière aléatoire
|
||||
* */
|
||||
|
||||
t1=tstamp();
|
||||
S= sum_array(array,access,size);
|
||||
t2=tstamp();
|
||||
|
||||
printf("S=%ld %lf\n",S,(t2-t1));
|
||||
|
||||
}
|
0
SCR/SCR3.1/TP01/bashrc
Normal file
0
SCR/SCR3.1/TP01/bashrc
Normal file
38
SCR/SCR3.1/TP02/Exercise1/copy_stdio.c
Normal file
38
SCR/SCR3.1/TP02/Exercise1/copy_stdio.c
Normal file
@@ -0,0 +1,38 @@
|
||||
//Correction
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define BLOCK_SIZE 1
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FILE* fin,
|
||||
* fout;
|
||||
char buf[BLOCK_SIZE];
|
||||
|
||||
assert( argc == 3 );
|
||||
|
||||
fin = fopen(argv[1], "r");
|
||||
assert( fin != NULL );
|
||||
|
||||
fout = fopen(argv[2],"w");
|
||||
assert( fout != NULL );
|
||||
|
||||
while(1){
|
||||
ssize_t nb_read;
|
||||
nb_read = fread(buf,BLOCK_SIZE,1,fin);
|
||||
if (nb_read <= 0)
|
||||
break;
|
||||
fwrite(buf,BLOCK_SIZE,nb_read,fout);
|
||||
}
|
||||
|
||||
fclose(fin);
|
||||
fclose(fout);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
37
SCR/SCR3.1/TP02/Exercise1/copy_sys.c
Normal file
37
SCR/SCR3.1/TP02/Exercise1/copy_sys.c
Normal file
@@ -0,0 +1,37 @@
|
||||
//Correction
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
|
||||
#define BLOCK_SIZE 1
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int fin,
|
||||
fout;
|
||||
char buf[BLOCK_SIZE];
|
||||
|
||||
assert( argc == 3 );
|
||||
|
||||
fin = open(argv[1],O_RDONLY);
|
||||
assert( fin >= 0 );
|
||||
|
||||
fout = open(argv[2],O_CREAT|O_WRONLY|O_TRUNC,0600);
|
||||
assert( fout >= 0 );
|
||||
|
||||
while(1){
|
||||
ssize_t nb_read;
|
||||
nb_read = read(fin,buf,BLOCK_SIZE);
|
||||
if (nb_read <= 0)
|
||||
break;
|
||||
write(fout,buf,nb_read);
|
||||
}
|
||||
|
||||
close(fin);
|
||||
close(fout);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
70
SCR/SCR3.1/TP02/Exercise2/copy.c
Normal file
70
SCR/SCR3.1/TP02/Exercise2/copy.c
Normal file
@@ -0,0 +1,70 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <assert.h>
|
||||
#include <time.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
|
||||
#define BUFSIZE 1024
|
||||
|
||||
|
||||
static inline double tstamp(void)
|
||||
{
|
||||
struct timespec tv;
|
||||
clock_gettime(CLOCK_REALTIME, &tv);
|
||||
return tv.tv_sec + tv.tv_nsec * 1.0e-9;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
//char buf[BUFSIZE];
|
||||
char * bufin = NULL,
|
||||
* bufout = NULL;
|
||||
|
||||
|
||||
int fin,
|
||||
fout;
|
||||
|
||||
double start,
|
||||
end;
|
||||
|
||||
size_t filesize = 0;
|
||||
|
||||
assert(argc == 3);
|
||||
|
||||
start = tstamp();
|
||||
|
||||
fin = open(argv[1],O_RDONLY);
|
||||
assert(fin >=0);
|
||||
|
||||
fout = open(argv[2],O_RDWR|O_CREAT|O_TRUNC,0600);
|
||||
assert(fout >=0);
|
||||
|
||||
filesize = lseek(fin,0,SEEK_END);
|
||||
ftruncate (fout,filesize);
|
||||
|
||||
bufin = mmap(NULL,filesize,PROT_READ,MAP_PRIVATE,fin,0);
|
||||
assert(bufin != (void*)-1);
|
||||
|
||||
bufout = mmap(NULL,filesize,PROT_WRITE,MAP_SHARED,fout,0);
|
||||
|
||||
assert(bufout != (void*)-1);
|
||||
|
||||
|
||||
memcpy(bufout,bufin,filesize);
|
||||
|
||||
//munmap(bufin,filesize);
|
||||
//munmap(bufout,filesize);
|
||||
|
||||
//ssize_t nb_read = read(fin,buf,sizeof(buf));
|
||||
close(fin);
|
||||
close(fout);
|
||||
|
||||
end = tstamp();
|
||||
|
||||
printf("time = %.3lf\n",end - start);
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user