2 meinOS - A unix-like x86 microkernel operating system
3 Copyright (C) 2008 Janosch Gräf <janosch.graef@gmx.net>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include <sys/types.h>
25 int _create_unnamed_pipe(int read
,int *_shmid
);
28 * Creates a new process from executable file
29 * @param path Path to executable
30 * @param argv Argument vector
31 * @param stdin Reference for filehandle for stdin of new process
32 * @param stdout Reference for filehandle for stdout of new process
33 * @param stderr Reference for filehandle for stderr of new process
34 * @return PID of new process
36 pid_t
execute(const char *path
,char *argv
[],int *_stdin
,int *_stdout
,int *_stderr
) {
37 size_t shmsize
= sizeof(struct process_data
)+1;
39 struct process_data
*data
;
43 for (i
=0;argv
[i
];i
++) shmsize
+= strlen(argv
[i
])+1;
45 shmid
= shmget(IPC_PRIVATE
,shmsize
,0);
48 data
= shmat(shmid
,NULL
,0);
50 int stdin
= _create_unnamed_pipe(0,&(data
->shmid_stdin
));
51 int stdout
= _create_unnamed_pipe(1,&(data
->shmid_stdout
));
52 int stderr
= _create_unnamed_pipe(1,&(data
->shmid_stderr
));
53 if (_stdin
!=NULL
) *_stdin
= stdin
;
54 if (_stdout
!=NULL
) *_stdout
= stdout
;
55 if (_stderr
!=NULL
) *_stderr
= stderr
;
60 for (i
=0;argv
[i
];i
++) {
61 strcpy(data
->cmdline
+j
,argv
[i
]);
62 j
+= strlen(data
->cmdline
+j
)+1;
69 return rpc_call("proc_execute",0,path
,shmid
);