Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9ec8748

Browse files
optiklaboptiklab
optiklab
authored and
optiklab
committed
Commit from MACOSX to unify diffs
1 parent de183ec commit 9ec8748

31 files changed

+3744
-3744
lines changed

‎README.md

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
# multithreaded-network-programming-examples
2-
I'm learning network programming in C/C++ with using of multiplexing, multiprocessing or multithreading features available in Debian (and most Linux based OS). Currently I'm using sockets, however I'm open to continue with RPC, web-sockets, any so on.
3-
4-
I'm getting examples and training tasks from different books and online courses. Here is list of books I read to get good understanding of theory:
5-
* Tanenbaum A.S. Operating systems design and implementation.
6-
* Stevens W.R. TCP IP Illustrated. Part 1. The Protocols
7-
* Stevens W.R. TCP IP Illustrated. Part 2. The Implementation
8-
9-
Online-courses available for Russians:
10-
* Multithreaded programming in C++ https://stepic.org/course/%D0%9C%D0%BD%D0%BE%D0%B3%D0%BE%D0%BF%D0%BE%D1%82%D0%BE%D1%87%D0%BD%D0%BE%D0%B5-%D0%BF%D1%80%D0%BE%D0%B3%D1%80%D0%B0%D0%BC%D0%BC%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5-%D0%BD%D0%B0-%D0%A1%D0%A1%2B%2B-149/
11-
* Highload cource from Mail.Ru https://www.youtube.com/watch?v=uYhQ2ot3XFg
12-
* Many videos from Highload conference in Russia http://www.highload.ru/
13-
14-
Good papers to read:
15-
* What Every Dev Must Know About Multithreaded Apps (about .NET)
16-
* Pedro Ramalhete, Andreia Correia. Left-Right: A Concurrency Control Technique with Wait-Free Population Oblivious Reads
17-
18-
Books I need to read (as you see - a lot of work TODO):
19-
* Mark Richards. Microservices vs. Service-Oriented Architecture
20-
* Stevens W.R. Unix Network Programming Vol.2. Second edition. Interprocess communications.
21-
* Paul E. McKenney. Is Parallel Programming Hard, And, If So, What Can You Do About It?
22-
* Jon C. Snader. Effective TCP/IP Programming
23-
* Effective TCP/IP Programming
24-
* Michael K. Johnson, Erik W. Troan. Linux Application Development
25-
* Stevens W.R. Advanced Programming in the UNIX Environment
26-
27-
To keep all this information in my mind I'm using notes in Microsoft OneNote application (which is free and available on all platforms and in the web), so if you need any info, I'm ready to share these notes too.
28-
29-
I'm continue to read books, papers and articles, to learn video-courses available online, so I'm filling this collection of examples and trying to fix possible problems. So, any fixes and suggestions are welcome.
1+
# multithreaded-network-programming-examples
2+
I'm learning network programming in C/C++ with using of multiplexing, multiprocessing or multithreading features available in Debian (and most Linux based OS). Currently I'm using sockets, however I'm open to continue with RPC, web-sockets, any so on.
3+
4+
I'm getting examples and training tasks from different books and online courses. Here is list of books I read to get good understanding of theory:
5+
* Tanenbaum A.S. Operating systems design and implementation.
6+
* Stevens W.R. TCP IP Illustrated. Part 1. The Protocols
7+
* Stevens W.R. TCP IP Illustrated. Part 2. The Implementation
8+
9+
Online-courses available for Russians:
10+
* Multithreaded programming in C++ https://stepic.org/course/%D0%9C%D0%BD%D0%BE%D0%B3%D0%BE%D0%BF%D0%BE%D1%82%D0%BE%D1%87%D0%BD%D0%BE%D0%B5-%D0%BF%D1%80%D0%BE%D0%B3%D1%80%D0%B0%D0%BC%D0%BC%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5-%D0%BD%D0%B0-%D0%A1%D0%A1%2B%2B-149/
11+
* Highload cource from Mail.Ru https://www.youtube.com/watch?v=uYhQ2ot3XFg
12+
* Many videos from Highload conference in Russia http://www.highload.ru/
13+
14+
Good papers to read:
15+
* What Every Dev Must Know About Multithreaded Apps (about .NET)
16+
* Pedro Ramalhete, Andreia Correia. Left-Right: A Concurrency Control Technique with Wait-Free Population Oblivious Reads
17+
18+
Books I need to read (as you see - a lot of work TODO):
19+
* Mark Richards. Microservices vs. Service-Oriented Architecture
20+
* Stevens W.R. Unix Network Programming Vol.2. Second edition. Interprocess communications.
21+
* Paul E. McKenney. Is Parallel Programming Hard, And, If So, What Can You Do About It?
22+
* Jon C. Snader. Effective TCP/IP Programming
23+
* Effective TCP/IP Programming
24+
* Michael K. Johnson, Erik W. Troan. Linux Application Development
25+
* Stevens W.R. Advanced Programming in the UNIX Environment
26+
27+
To keep all this information in my mind I'm using notes in Microsoft OneNote application (which is free and available on all platforms and in the web), so if you need any info, I'm ready to share these notes too.
28+
29+
I'm continue to read books, papers and articles, to learn video-courses available online, so I'm filling this collection of examples and trying to fix possible problems. So, any fixes and suggestions are welcome.

‎multithreading/00 - Fork Processes.c

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
1-
#include <stdio.h>
2-
#include <stdlib.h>
3-
#include <fcntl.h>
4-
#include <unistd.h>
5-
#include <sys/wait.h> // For wait, waitpid
6-
7-
#define PORTNUM 1500 // Port > 1024 because program will not work not as root.
8-
#define NUMBER_OF_PROCESSES 2
9-
#define EXIT_FAILURE 1
10-
11-
// Compilation:
12-
// gcc -std=gnu99 "00 - Fork Processes.c" -o forkProcesses
13-
14-
// Task:
15-
// Use fork to create a child process.
16-
17-
int main(int argc, char *argv[])
18-
{
19-
printf("Enter to main!\n");
20-
for (int i = 0; i < NUMBER_OF_PROCESSES; i++)
21-
{
22-
pid_t pid;
23-
int status;
24-
switch(pid=fork())
25-
{
26-
case -1:
27-
printf("PROC %d:", i);
28-
perror("1 Error of calling fork");
29-
exit(EXIT_FAILURE);
30-
case 0:
31-
printf("PROC %d: 1 CHILD: Child process %d!\n", i, getpid());
32-
printf("PROC %d: 2 CHILD: Parent PID %d!\n", i, getppid());
33-
printf("PROC %d: 3 CHILD: Wait 10 seconds...\n", i);
34-
sleep(10);
35-
printf("PROC %d: 4 CHILD: Exit!\n", i);
36-
exit(EXIT_FAILURE);
37-
default:
38-
printf("PROC %d: 1 PARENT: Parent process %d!\n", i, getpid());
39-
printf("PROC %d: 2 PARENT: Child PID %d\n", i, pid);
40-
printf("PROC %d: 3 PARENT: Wait until child calls exit()...\n", i);
41-
waitpid(pid, &status, 0);
42-
printf("PROC %d: 4 PARENT: Child exit code: %d\n", i, WEXITSTATUS(status));
43-
printf("PROC %d: 5 PARENT: Exit!\n", i);
44-
}
45-
}
46-
47-
printf("Exit main!\n");
48-
exit(0);
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <fcntl.h>
4+
#include <unistd.h>
5+
#include <sys/wait.h> // For wait, waitpid
6+
7+
#define PORTNUM 1500 // Port > 1024 because program will not work not as root.
8+
#define NUMBER_OF_PROCESSES 2
9+
#define EXIT_FAILURE 1
10+
11+
// Compilation:
12+
// gcc -std=gnu99 "00 - Fork Processes.c" -o forkProcesses
13+
14+
// Task:
15+
// Use fork to create a child process.
16+
17+
int main(int argc, char *argv[])
18+
{
19+
printf("Enter to main!\n");
20+
for (int i = 0; i < NUMBER_OF_PROCESSES; i++)
21+
{
22+
pid_t pid;
23+
int status;
24+
switch(pid=fork())
25+
{
26+
case -1:
27+
printf("PROC %d:", i);
28+
perror("1 Error of calling fork");
29+
exit(EXIT_FAILURE);
30+
case 0:
31+
printf("PROC %d: 1 CHILD: Child process %d!\n", i, getpid());
32+
printf("PROC %d: 2 CHILD: Parent PID %d!\n", i, getppid());
33+
printf("PROC %d: 3 CHILD: Wait 10 seconds...\n", i);
34+
sleep(10);
35+
printf("PROC %d: 4 CHILD: Exit!\n", i);
36+
exit(EXIT_FAILURE);
37+
default:
38+
printf("PROC %d: 1 PARENT: Parent process %d!\n", i, getpid());
39+
printf("PROC %d: 2 PARENT: Child PID %d\n", i, pid);
40+
printf("PROC %d: 3 PARENT: Wait until child calls exit()...\n", i);
41+
waitpid(pid, &status, 0);
42+
printf("PROC %d: 4 PARENT: Child exit code: %d\n", i, WEXITSTATUS(status));
43+
printf("PROC %d: 5 PARENT: Exit!\n", i);
44+
}
45+
}
46+
47+
printf("Exit main!\n");
48+
exit(0);
4949
}

‎multithreading/01 - Signals_SIGCHLD.c

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
1-
#include <signal.h>
2-
#include <stdio.h>
3-
#include <stdlib.h>
4-
#include <unistd.h>
5-
6-
#include "Common.h"
7-
8-
// To compile:
9-
// gcc -std=gnu99 "01 - Signals_SIGCHLD.c" -o signals_sigchld
10-
11-
// Task:
12-
// Create a program which creates a child process and handles SIGCHLD signal from its childs.
13-
14-
int main()
15-
{
16-
pid_t main_pid = getpid();
17-
18-
printf("Start of process %d\n", main_pid);
19-
20-
// Handle child process killing.
21-
handle_child_finishing();
22-
23-
// Make child.
24-
pid_t child_pid;
25-
if((child_pid = fork()))
26-
{
27-
printf("PARENT: Started child process %d.\n", child_pid);
28-
29-
printf("PARENT: Parent process works 1 second.\n");
30-
31-
sleep(1);
32-
}
33-
else
34-
{
35-
// Do anything in child.
36-
}
37-
38-
printf("End of process %d\n", getpid());
39-
40-
exit(0);
41-
}
1+
#include <signal.h>
2+
#include <stdio.h>
3+
#include <stdlib.h>
4+
#include <unistd.h>
5+
6+
#include "Common.h"
7+
8+
// To compile:
9+
// gcc -std=gnu99 "01 - Signals_SIGCHLD.c" -o signals_sigchld
10+
11+
// Task:
12+
// Create a program which creates a child process and handles SIGCHLD signal from its childs.
13+
14+
int main()
15+
{
16+
pid_t main_pid = getpid();
17+
18+
printf("Start of process %d\n", main_pid);
19+
20+
// Handle child process killing.
21+
handle_child_finishing();
22+
23+
// Make child.
24+
pid_t child_pid;
25+
if((child_pid = fork()))
26+
{
27+
printf("PARENT: Started child process %d.\n", child_pid);
28+
29+
printf("PARENT: Parent process works 1 second.\n");
30+
31+
sleep(1);
32+
}
33+
else
34+
{
35+
// Do anything in child.
36+
}
37+
38+
printf("End of process %d\n", getpid());
39+
40+
exit(0);
41+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /