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 b6e1d66

Browse files
optiklaboptiklab
optiklab
authored and
optiklab
committed
Minor fixes in namedpipes.
1 parent 93b127d commit b6e1d66

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

‎multithreading/03 - Nonamed_pipes.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ void run(CmdLine* command)
2525
{
2626
const int numPipes = 3;
2727
int i = 0;
28-
pid_t pid;
2928

3029
// Create all pipes.
3130
int pipefds[2*numPipes];
@@ -39,6 +38,7 @@ void run(CmdLine* command)
3938
}
4039

4140
int j = 0;
41+
pid_t pid;
4242
while(command)
4343
{
4444
pid = fork();

‎multithreading/03 - Nonamed_pipes_read_write.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// Task:
1313
// Do write on one end and read on another end.
1414

15-
void main()
15+
int main()
1616
{
1717
int fd[2], nbytes;
1818
pid_t childpid;

‎multithreading/03 - Nonamed_pipes_wc_logins.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <stdio.h>
2+
#include <stdlib.h>
23
#include <unistd.h>
34

45
// Compilation:
@@ -10,7 +11,7 @@
1011

1112
// Help:
1213
// Create pipe: who -> stdout -> [pfd[1] -> pfd[0]] -> stdin -> wc -l
13-
void main()
14+
int main()
1415
{
1516
printf("Result of operation is the same like if you type\n$>who | wc -l\n");
1617

‎multithreading/04 - Named_pipes.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// Task:
1515
// Create Named Pipe aka FIFO to do write on one end and read on another end.
1616

17-
void main()
17+
int main()
1818
{
1919
char * myfifo = "/tmp/myfifo";
2020
mkfifo(myfifo, 0666);
@@ -31,7 +31,7 @@ void main()
3131
{
3232
char string[] = "Hello, world!";
3333
int fd;
34-
if (fd = open(myfifo, O_WRONLY))
34+
if ((fd = open(myfifo, O_WRONLY)))
3535
{
3636
write(fd, string, (strlen(string)+1));
3737
close(fd);
@@ -46,7 +46,7 @@ void main()
4646

4747
char readbuffer[80];
4848
int fd;
49-
if (fd = open(myfifo, O_RDONLY))
49+
if ((fd = open(myfifo, O_RDONLY)))
5050
{
5151
read(fd, readbuffer, 80);
5252
printf("Process %d received string: %s\n", getpid(), readbuffer);

0 commit comments

Comments
(0)

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