pa-04
This commit is contained in:
6
pa-06/a1/a.c
Normal file
6
pa-06/a1/a.c
Normal file
@@ -0,0 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
int main(void) {
|
||||
printf("Guten Tag %d\n", fork());
|
||||
return 0;
|
||||
}
|
||||
6
pa-06/a1/b.c
Normal file
6
pa-06/a1/b.c
Normal file
@@ -0,0 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
int main(void) {
|
||||
printf("Guten %d Tag %d\n", fork(), fork());
|
||||
return 0;
|
||||
}
|
||||
7
pa-06/a1/c.c
Normal file
7
pa-06/a1/c.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
int main(void) {
|
||||
printf("Guten %d\n", fork());
|
||||
printf("Tag %d\n", fork());
|
||||
return 0;
|
||||
}
|
||||
21
pa-06/a1/d.c
Normal file
21
pa-06/a1/d.c
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
int main(void) {
|
||||
int v1 = 0, v2 = 0, v3 = 0, pid;
|
||||
pid = getpid();
|
||||
v2++;
|
||||
if (fork()) {
|
||||
v1++;
|
||||
v2++;
|
||||
sleep(1);
|
||||
if (fork()) {
|
||||
v1++;
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
if (pid == getppid()) {
|
||||
v3++;
|
||||
}
|
||||
printf("%d %d %d\n", v1, v2, v3);
|
||||
return 0;
|
||||
}
|
||||
61
pa-06/a1/flake.lock
generated
Normal file
61
pa-06/a1/flake.lock
generated
Normal file
@@ -0,0 +1,61 @@
|
||||
{
|
||||
"nodes": {
|
||||
"flake-parts": {
|
||||
"inputs": {
|
||||
"nixpkgs-lib": "nixpkgs-lib"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1763759067,
|
||||
"narHash": "sha256-LlLt2Jo/gMNYAwOgdRQBrsRoOz7BPRkzvNaI/fzXi2Q=",
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"rev": "2cccadc7357c0ba201788ae99c4dfa90728ef5e0",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1763835633,
|
||||
"narHash": "sha256-HzxeGVID5MChuCPESuC0dlQL1/scDKu+MmzoVBJxulM=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "050e09e091117c3d7328c7b2b7b577492c43c134",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs-lib": {
|
||||
"locked": {
|
||||
"lastModified": 1761765539,
|
||||
"narHash": "sha256-b0yj6kfvO8ApcSE+QmA6mUfu8IYG6/uU28OFn4PaC8M=",
|
||||
"owner": "nix-community",
|
||||
"repo": "nixpkgs.lib",
|
||||
"rev": "719359f4562934ae99f5443f20aa06c2ffff91fc",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-community",
|
||||
"repo": "nixpkgs.lib",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-parts": "flake-parts",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
60
pa-06/a1/flake.nix
Normal file
60
pa-06/a1/flake.nix
Normal file
@@ -0,0 +1,60 @@
|
||||
{
|
||||
description = "Description for the project";
|
||||
|
||||
inputs = {
|
||||
flake-parts.url = "github:hercules-ci/flake-parts";
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
};
|
||||
|
||||
outputs = inputs @ {flake-parts, ...}:
|
||||
flake-parts.lib.mkFlake {inherit inputs;} {
|
||||
imports = [
|
||||
# To import an internal flake module: ./other.nix
|
||||
# To import an external flake module:
|
||||
# 1. Add foo to inputs
|
||||
# 2. Add foo as a parameter to the outputs function
|
||||
# 3. Add here: foo.flakeModule
|
||||
];
|
||||
systems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin"];
|
||||
perSystem = {
|
||||
config,
|
||||
self',
|
||||
inputs',
|
||||
pkgs,
|
||||
system,
|
||||
...
|
||||
}: let
|
||||
mkTask = part:
|
||||
pkgs.stdenv.mkDerivation {
|
||||
name = "a1-${part}";
|
||||
src = ./.;
|
||||
buildPhase = ''
|
||||
cc ${part}.c -o ${part}.out
|
||||
'';
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin/
|
||||
mv ${part}.out $out/bin/
|
||||
'';
|
||||
meta = {
|
||||
mainProgram = "${part}.out";
|
||||
};
|
||||
};
|
||||
in {
|
||||
# Per-system attributes can be defined here. The self' and inputs'
|
||||
# module parameters provide easy access to attributes of the same
|
||||
# system.
|
||||
|
||||
packages = {
|
||||
a = mkTask "a";
|
||||
b = mkTask "b";
|
||||
c = mkTask "c";
|
||||
d = mkTask "d";
|
||||
};
|
||||
};
|
||||
flake = {
|
||||
# The usual flake attributes can be defined here, including system-
|
||||
# agnostic ones like nixosModule and system-enumerating ones, although
|
||||
# those are more easily expressed in perSystem.
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user