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@DDPåtd¨	¨	@¨	@44QåtdRåtd``ðð/lib64/ld-linux-x86-64.so.2GNU GNUqÉ«f=j+_´ Ÿ8{ƒ—ªD&!2J ,libc.so.6pipeputsforkprintfreadclosesleep__libc_start_mainwrite__gmon_start__GLIBC_2.2.5ui	Yø`` `(`0`8`@`H`P`X`	``
HƒìH‹…
 H…Àtè“HƒÄÃÿ5r
 ÿ%t
 @ÿ%r
 héàÿÿÿÿ%j
 héÐÿÿÿÿ%b
 héÀÿÿÿÿ%Z
 hé°ÿÿÿÿ%R
 hé ÿÿÿÿ%J
 hé�ÿÿÿÿ%B
 hé€ÿÿÿÿ%:
 hépÿÿÿÿ%2
 hé`ÿÿÿÿ%*
 h	éPÿÿÿ1íI‰Ñ^H‰âHƒäðPTIÇÀà@HÇÁp@HÇÇ6@è—ÿÿÿôfD¸w`UH-p`HƒøH‰åv¸H…Àt]¿p`ÿàf„]Ãfffff.„¾p`UH�îp`HÁþH‰åH‰ðHÁè?HÆHÑþt¸H…Àt]¿p`ÿà]ÃfD€=u	 uUH‰åènÿÿÿ]Æb	 óÃ@¿ `Hƒ?u듸H…ÀtñUH‰åÿÐ]ézÿÿÿUH‰åHƒì0¿	@èXþÿÿH�EàH‰ÇèŒþÿÿƒøÿu¿	@è=þÿÿ¸ÿÿÿÿéÿè¾þÿÿ‰Eüƒ}ü„œ¿$	@èþÿÿ‹Eà‰Çè=þÿÿHÇEð>	@HÇEèU	@H‹EðH‰Æ¿l	@¸èþÿÿ‹EäH‹MðºH‰Î‰Çèáýÿÿ¿èGþÿÿH‹EèH‰Æ¿l	@¸èÑýÿÿ‹EäH‹MèºH‰Î‰Çè«ýÿÿ‹Eä‰ÇèÁýÿÿ¿€	@è‡ýÿÿëQ¿Œ	@è{ýÿÿ‹Eä‰Çè¡ýÿÿëH�EßH‰Çècýÿÿ‹EàH�MߺH‰Î‰Çè�ýÿÿH…ÀuÙ‹Eà‰Çènýÿÿ¿š	@è4ýÿÿÉÃf�AWAVA‰ÿAUATL�%Ž UH�-Ž SI‰öI‰Õ1ÛL)åHƒìHÁýèÅüÿÿH…ít„L‰êL‰öD‰ÿAÿÜHƒÃH9ëuêHƒÄ[]A\A]A^A_Ãff.„óÃHƒìHƒÄÃParent runningPipe creation failedParent running after forkprinting to the pipe.putting more in pipe.Parent writing: %s
Parent doneChild runningChild done;4èûÿÿ€˜üÿÿPŽýÿÿ¨ÈþÿÿÈ8ÿÿÿzRx�@üÿÿ*zRx�$`ûÿÿ°FJw€?;*3$"DÞüÿÿ8A†C
3DdøýÿÿeB�BŽE �B(ŒH0†H8ƒO@p8A0A(B BBB¬ þÿÿ@ð@h@
ä@``õþÿo˜@À@¸@
e`ðx@`@	þÿÿo@@ÿÿÿoðÿÿo&@(`¦@¶@Æ@Ö@æ@ö@@@&@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$Döÿÿo˜@˜N¸@¸VÀ@Àe^ÿÿÿo&@&kþÿÿo@@@ z`@`„x@xðŽh@h‰�@�°”@@@¢šä@ä	 ð@𵨨	@¨	4¶à	@à	ôÀ`Ì`Ø ` Ý(`(Ðæø`øë`hôh`húl`lÿ0l,˜ À-	à½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/css/themes/spacelab.min.css" />
<link rel="stylesheet" type="text/css" href="http://www.cs.wlu.edu/~sprenkle/cs330/css/course.css" />
<link rel="stylesheet" type="text/css" href="http://www.cs.wlu.edu/~sprenkle/cs330/css/syntax.css" />
<link rel="stylesheet" type="text/css" href="http://www.cs.wlu.edu/~sprenkle/cs330/css/style.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.