Contents

  1. .
  2. ./a.out
  3. ./index.html
  4. ./pipedemo.c
  5. ./sharedmem.c

. 1/5

[
top][prev][next]


./a.out 2/5

[
top][prev][next]
ELF>@@@@8	@@@@@@88@8@@@

 ``\` ((`(`TT@T@DDPtd		@	@44QtdRtd``/lib64/ld-linux-x86-64.so.2GNU GNUqf=j+_ 8{D&!2J ,libc.so.6pipeputsforkprintfreadclosesleep__libc_start_mainwrite__gmon_start__GLIBC_2.2.5ui	Y`` `(`0`8`@`H`P`X`	``
HH
 HtH5r
 %t
 @%r
 h%j
 h%b
 h%Z
 h%R
 h%J
 h%B
 h%:
 hp%2
 h`%*
 h	P1I^HHPTI@Hp@H6@fDw`UH-p`HHvHt]p`f]fffff.p`UHp`HHHH?HHtHt]p`]fD=u	 uUHn]b	 @ `H?uHtUH]zUHH0	@XHEHu	@=E}$	@E=HE>	@HEU	@HEHƿl	@EHMHΉGHEHƿl	@EHMHΉE	@Q	@{EHEHcEHMߺHΉHuًEn	@4fAWAVAAUATL% UH- SII1L)HHHtLLDAHH9uH[]A\A]A^A_ff.HHParent runningPipe creation failedParent running after forkprinting to the pipe.putting more in pipe.Parent writing: %s
Parent doneChild runningChild done;4P8zRx@*zRx$`FJw?;*3$"D8AC
3DdeBBE B(H0H8O@p8A0A(B BBB @@h@
@``o@@@
e`x@`@	o@@oo&@(`@@@@@@@@&@6@GCC: (GNU) 4.9.2 20150212 (Red Hat 4.9.2-6).symtab.strtab.shstrtab.interp.note.ABI-tag.note.gnu.build-id.gnu.hash.dynsym.dynstr.gnu.version.gnu.version_r.rela.dyn.rela.plt.init.text.fini.rodata.eh_frame_hdr.eh_frame.init_array.fini_array.jcr.dynamic.got.got.plt.data.bss.comment8@8#T@T 1t@t$Do@N@V@e^o&@&ko@@@ z`@`x@xh@h@@@@@	@	@	4	@	`` ` (`(``hh`hl`l0l, -	8@T@t@@@@&@@@	`@
x@h@@
@@@@	@	@`` `(```h`l` `
p@.
@A
@Wl`f`
@`
@ ``(``
` 
@0 L h`Wi|l`@h` @@+
p@e;p`@
@@Gl`S
6@8X lp`x h@crtstuff.c__JCR_LIST__deregister_tm_clonesregister_tm_clones__do_global_dtors_auxcompleted.6636__do_global_dtors_aux_fini_array_entryframe_dummy__frame_dummy_init_array_entrypipedemo.c__FRAME_END____JCR_END____init_array_end_DYNAMIC__init_array_start_GLOBAL_OFFSET_TABLE___libc_csu_fini_ITM_deregisterTMCloneTabledata_startputs@@GLIBC_2.2.5write@@GLIBC_2.2.5_edata_finiprintf@@GLIBC_2.2.5close@@GLIBC_2.2.5pipe@@GLIBC_2.2.5read@@GLIBC_2.2.5__libc_start_main@@GLIBC_2.2.5__data_start__gmon_start____dso_handle_IO_stdin_used__libc_csu_init_end_start__bss_startmain_Jv_RegisterClasses__TMC_END___ITM_registerTMCloneTablesleep@@GLIBC_2.2.5_initfork@@GLIBC_2.2.5

./index.html 3/5

[
top][prev][next]
<html>
<head><title>Examples for /home/faculty/sprenkle/public_html/cs330/examples/12-ipc</title>
<link rel="stylesheet" type="text/css" href="http://www.cs.wlu.edu/~sprenkle/cs330/assignments/assign.css" />
</head>
<body>
<h1>Examples for /home/faculty/sprenkle/public_html/cs330/examples/12-ipc</h1>
<ul>
<li><a href=".//code.html">All IN ONE FILE (pretty syntax)</a>
<li><a href=".//a.out">a.out</a></li>
<li><a href=".//pipedemo.c">pipedemo.c</a></li>
<li><a href=".//sharedmem.c">sharedmem.c</a></li>
</ul>
</body>

./pipedemo.c 4/5

[
top][prev][next]
/*
 * Demonstration of how to create and use an Unnamed
 * Unix pipe to communicate between a parent and a
 * child.
 */
 
#include <stdio.h>		// for printf
#include <unistd.h>		// for fork & pipe stuff.
#include <sys/wait.h>	// for wait

#define READ_END 0
#define WRITE_END 1

int main() {

	printf("Parent running\n");
     
	// Create the pipe before the fork so that the child
	// process has a copy of it after the fork.
	int fd[2];
	if (pipe(fd) == -1) {
		printf("Pipe creation failed\n");
		return -1;
	}

	// Create child process.
	int pid = fork();
   
	// fork returns pid of child process in parent
	// and 0 in the child.
	if (pid != 0) {
		printf("Parent running after fork\n");
     
		// The parent will write to the pipe.  So close
		// the read end of the pipe and begin writing data.
		close(fd[READ_END]);
		char *str1 = "printing to the pipe.\0";
		char *str2 = "putting more in pipe.\0";
		
		printf("Parent writing: %s\n", str1);
		write(fd[WRITE_END], str1, 21);
		sleep(3);
		printf("Parent writing: %s\n", str2);
		write(fd[WRITE_END], str2, 21);

		close(fd[WRITE_END]);

		printf("Parent done\n");
	}
	else {
		printf("Child running\n");
		
		// The child will read from the pipe.  So close the
		// write end of the pipe and begin reading until the 
		// parent closes the pipe.
		close(fd[WRITE_END]);
		char buf[1];
		while(read(fd[READ_END], buf, 1) != 0) {
			printf("%s\n",buf);
		}
		close(fd[READ_END]);

		printf("Child done\n");
	}
}

./sharedmem.c 5/5

[
top][prev][next]
#include <stdio.h>
#include <sys/shm.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/wait.h>

int main() {
	
	int segID;

	// Create 4 bytes of shared memory.  Just enough for one int value.
	segID = shmget(IPC_PRIVATE, 4, S_IRUSR | S_IWUSR);

	int pid = fork();
	if (pid != 0) {
		// Get a pointer to the shared bytes for the parent.
		int *sharedInt = (int *) shmat(segID, NULL, 0);
	    // forced yield of the process
		//sleep(1);

		// Store the value 7 in the shared space.	
		sharedInt[0] = 7;
		
		printf("Parent Before: %d\n", sharedInt[0]);
		wait(NULL);
		printf("Parent After: %d\n", sharedInt[0]);
	}
	else {
		// Get a pointer to the shared bytes for the child.
		int *sharedInt = (int *) shmat(segID, NULL, 0);

		printf("Child Before: %d\n", sharedInt[0]);
		
		// Change the value stored in the shared space.
		sharedInt[0] = 9;

		printf("Child After: %d\n", sharedInt[0]);	
	}	
}

Generated by GNU Enscript 1.6.6.