
#include
#include
#include
#include
#include
struct st_pid
{
int pid;
char name[51];
};
int main(int argc, char *argv[])
{
int shmid;
if((shmid=shmget(0x5005, sizeof(struct st_pid), 0640|IPC_CREAT))==-1)
{ printf("shmget(0x0555) failed\n"); return -1;}
struct st_pid *stpid=0;
if((stpid=(struct st_pid *)shmat(shmid, 0, 0))==(void *)-1)
{ printf("shmat failed\n"); return -1; }
printf("pid=%d,name=%s\n", stpid->pid, stpid->name);
stpid->pid = getpid();
strcpy(stpid->name, argv[1]);
printf("pid=%d,name=%s\n", stpid->pid, stpid->name);
shmdt(stpid);
if (shmctl(shmid,IPC_RMID,0)==-1)
{ printf("shmctl failed\n"); return -1;}
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46